zstdlib 0.0.4__tar.gz → 0.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {zstdlib-0.0.4/zstdlib.egg-info → zstdlib-0.0.5}/PKG-INFO +1 -1
  2. {zstdlib-0.0.4 → zstdlib-0.0.5}/tests/test_frozen.py +4 -1
  3. {zstdlib-0.0.4 → zstdlib-0.0.5}/zstdlib/__init__.py +1 -1
  4. {zstdlib-0.0.4 → zstdlib-0.0.5}/zstdlib/frozen.py +25 -15
  5. {zstdlib-0.0.4 → zstdlib-0.0.5/zstdlib.egg-info}/PKG-INFO +1 -1
  6. {zstdlib-0.0.4 → zstdlib-0.0.5}/LICENSE +0 -0
  7. {zstdlib-0.0.4 → zstdlib-0.0.5}/README.md +0 -0
  8. {zstdlib-0.0.4 → zstdlib-0.0.5}/pyproject.toml +0 -0
  9. {zstdlib-0.0.4 → zstdlib-0.0.5}/setup.cfg +0 -0
  10. {zstdlib-0.0.4 → zstdlib-0.0.5}/tests/__init__.py +0 -0
  11. {zstdlib-0.0.4 → zstdlib-0.0.5}/tests/log/__init__.py +0 -0
  12. {zstdlib-0.0.4 → zstdlib-0.0.5}/tests/log/base.py +0 -0
  13. {zstdlib-0.0.4 → zstdlib-0.0.5}/tests/log/test_cute.py +0 -0
  14. {zstdlib-0.0.4 → zstdlib-0.0.5}/tests/log/test_trace.py +0 -0
  15. {zstdlib-0.0.4 → zstdlib-0.0.5}/tests/test_ansi.py +0 -0
  16. {zstdlib-0.0.4 → zstdlib-0.0.5}/tests/test_enum.py +0 -0
  17. {zstdlib-0.0.4 → zstdlib-0.0.5}/tests/test_singleton.py +0 -0
  18. {zstdlib-0.0.4 → zstdlib-0.0.5}/zstdlib/ansi.py +0 -0
  19. {zstdlib-0.0.4 → zstdlib-0.0.5}/zstdlib/enum.py +0 -0
  20. {zstdlib-0.0.4 → zstdlib-0.0.5}/zstdlib/log/__init__.py +0 -0
  21. {zstdlib-0.0.4 → zstdlib-0.0.5}/zstdlib/log/cute.py +0 -0
  22. {zstdlib-0.0.4 → zstdlib-0.0.5}/zstdlib/log/trace.py +0 -0
  23. {zstdlib-0.0.4 → zstdlib-0.0.5}/zstdlib/py.typed +0 -0
  24. {zstdlib-0.0.4 → zstdlib-0.0.5}/zstdlib/singleton.py +0 -0
  25. {zstdlib-0.0.4 → zstdlib-0.0.5}/zstdlib.egg-info/SOURCES.txt +0 -0
  26. {zstdlib-0.0.4 → zstdlib-0.0.5}/zstdlib.egg-info/dependency_links.txt +0 -0
  27. {zstdlib-0.0.4 → zstdlib-0.0.5}/zstdlib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zstdlib
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
@@ -78,7 +78,7 @@ class TestFrozen(unittest.TestCase):
78
78
  def test_metadata(self):
79
79
  @frozen
80
80
  class F2:
81
- def __init__(self):
81
+ def __init__(self, a: int = 1, *, b: bool = False) -> None:
82
82
  """
83
83
  init doc
84
84
  """
@@ -87,6 +87,9 @@ class TestFrozen(unittest.TestCase):
87
87
  self.assertEqual(f2.__init__.__doc__.strip(), "init doc")
88
88
  self.assertEqual(f2.__init__.__name__, "__init__")
89
89
  self.assertEqual(f2.__init__.__qualname__, "TestFrozen.test_metadata.<locals>.F2.__init__")
90
+ self.assertTupleEqual(f2.__init__.__defaults__, (1,))
91
+ self.assertDictEqual(f2.__init__.__kwdefaults__, {"b": False})
92
+ self.assertDictEqual(f2.__init__.__annotations__, {"a": int, "b": bool, "return": None})
90
93
 
91
94
  def test_frozen_custom(self):
92
95
  @frozen("custom")
@@ -1,4 +1,4 @@
1
- __version__ = "0.0.4"
1
+ __version__ = "0.0.5"
2
2
 
3
3
  from .frozen import Freezable, frozen
4
4
  from .singleton import Singleton
@@ -1,5 +1,16 @@
1
1
  from collections.abc import Callable
2
- from typing import TypeVar
2
+
3
+
4
+ _FN_ATTRS = (
5
+ "__annotations__",
6
+ "__type_params__",
7
+ "__qualname__",
8
+ "__module__",
9
+ "__name__",
10
+ "__doc__",
11
+ "__defaults__",
12
+ "__kwdefaults__",
13
+ )
3
14
 
4
15
 
5
16
  class Freezable:
@@ -41,40 +52,39 @@ class Freezable:
41
52
  super().__delattr__(item)
42
53
 
43
54
 
44
- _SELF = TypeVar("_SELF")
45
-
46
-
47
- def frozen(arg: str | type[_SELF]):
55
+ def frozen(arg: str | type):
48
56
  """
49
57
  A class decorator to permanently freeze a class after some method, __init__ by default
50
58
  If passed a string, will freeze after the method with that name
51
59
  """
52
60
 
53
- def shim_method(cls: type[_SELF], name, new) -> None:
61
+ def shim_method(cls: type, name, new) -> None:
54
62
  original = getattr(cls, name)
55
- new.__qualname__ = original.__qualname__
56
- new.__name__ = original.__name__
57
- new.__doc__ = original.__doc__
63
+ for i in _FN_ATTRS:
64
+ if hasattr(original, i):
65
+ setattr(new, i, getattr(original, i))
58
66
  setattr(cls, name, new)
59
67
 
60
- def mk_frozen(cls: type[_SELF], method: str) -> type:
68
+ def mk_frozen(cls: type, method: str) -> type:
61
69
  original_method: Callable = getattr(cls, method)
70
+ original_setattr: Callable = cls.__setattr__
71
+ original_delattr: Callable = cls.__delattr__
62
72
 
63
- def new_method(self: _SELF, *args, **kwargs):
73
+ def new_method(self, *args, **kwargs):
64
74
  ret = original_method(self, *args, **kwargs)
65
75
  # pylint: disable=protected-access
66
76
  self._frozen = True # type: ignore[attr-defined]
67
77
  return ret
68
78
 
69
- def __setattr__(self: _SELF, key: str, value) -> None:
79
+ def __setattr__(self, key: str, value):
70
80
  if getattr(self, "_frozen", False):
71
81
  raise AttributeError("Cannot modify frozen object")
72
- super(cls, self).__setattr__(key, value) # type: ignore[misc]
82
+ return original_setattr(self, key, value)
73
83
 
74
- def __delattr__(self: _SELF, item: str) -> None:
84
+ def __delattr__(self, item: str):
75
85
  if getattr(self, "_frozen", False):
76
86
  raise AttributeError("Cannot modify frozen object")
77
- super(cls, self).__delattr__(item) # type: ignore[misc]
87
+ return original_delattr(self, item)
78
88
 
79
89
  # Update cls with the new methods
80
90
  shim_method(cls, method, new_method)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zstdlib
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes