zstdlib 0.0.4__tar.gz → 0.0.6__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 (29) hide show
  1. {zstdlib-0.0.4/zstdlib.egg-info → zstdlib-0.0.6}/PKG-INFO +1 -1
  2. zstdlib-0.0.6/tests/not_set.py +15 -0
  3. {zstdlib-0.0.4 → zstdlib-0.0.6}/tests/test_frozen.py +4 -1
  4. {zstdlib-0.0.4 → zstdlib-0.0.6}/zstdlib/__init__.py +2 -1
  5. {zstdlib-0.0.4 → zstdlib-0.0.6}/zstdlib/frozen.py +25 -15
  6. zstdlib-0.0.6/zstdlib/not_set.py +12 -0
  7. {zstdlib-0.0.4 → zstdlib-0.0.6/zstdlib.egg-info}/PKG-INFO +1 -1
  8. {zstdlib-0.0.4 → zstdlib-0.0.6}/zstdlib.egg-info/SOURCES.txt +2 -0
  9. {zstdlib-0.0.4 → zstdlib-0.0.6}/LICENSE +0 -0
  10. {zstdlib-0.0.4 → zstdlib-0.0.6}/README.md +0 -0
  11. {zstdlib-0.0.4 → zstdlib-0.0.6}/pyproject.toml +0 -0
  12. {zstdlib-0.0.4 → zstdlib-0.0.6}/setup.cfg +0 -0
  13. {zstdlib-0.0.4 → zstdlib-0.0.6}/tests/__init__.py +0 -0
  14. {zstdlib-0.0.4 → zstdlib-0.0.6}/tests/log/__init__.py +0 -0
  15. {zstdlib-0.0.4 → zstdlib-0.0.6}/tests/log/base.py +0 -0
  16. {zstdlib-0.0.4 → zstdlib-0.0.6}/tests/log/test_cute.py +0 -0
  17. {zstdlib-0.0.4 → zstdlib-0.0.6}/tests/log/test_trace.py +0 -0
  18. {zstdlib-0.0.4 → zstdlib-0.0.6}/tests/test_ansi.py +0 -0
  19. {zstdlib-0.0.4 → zstdlib-0.0.6}/tests/test_enum.py +0 -0
  20. {zstdlib-0.0.4 → zstdlib-0.0.6}/tests/test_singleton.py +0 -0
  21. {zstdlib-0.0.4 → zstdlib-0.0.6}/zstdlib/ansi.py +0 -0
  22. {zstdlib-0.0.4 → zstdlib-0.0.6}/zstdlib/enum.py +0 -0
  23. {zstdlib-0.0.4 → zstdlib-0.0.6}/zstdlib/log/__init__.py +0 -0
  24. {zstdlib-0.0.4 → zstdlib-0.0.6}/zstdlib/log/cute.py +0 -0
  25. {zstdlib-0.0.4 → zstdlib-0.0.6}/zstdlib/log/trace.py +0 -0
  26. {zstdlib-0.0.4 → zstdlib-0.0.6}/zstdlib/py.typed +0 -0
  27. {zstdlib-0.0.4 → zstdlib-0.0.6}/zstdlib/singleton.py +0 -0
  28. {zstdlib-0.0.4 → zstdlib-0.0.6}/zstdlib.egg-info/dependency_links.txt +0 -0
  29. {zstdlib-0.0.4 → zstdlib-0.0.6}/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.6
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
@@ -0,0 +1,15 @@
1
+ import unittest
2
+
3
+ from zstdlib import NotSetType, NotSet
4
+
5
+
6
+ class TestNotSet(unittest.TestCase):
7
+ def test_not_set(self):
8
+ self.assertIsInstance(NotSetType, type)
9
+ self.assertIsInstance(NotSet, NotSetType)
10
+ self.assertIsNot(None, NotSet)
11
+ self.assertIs(NotSet, NotSetType())
12
+
13
+
14
+ if __name__ == "__main__":
15
+ unittest.main()
@@ -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,5 +1,6 @@
1
- __version__ = "0.0.4"
1
+ __version__ = "0.0.6"
2
2
 
3
+ from .not_set import NotSetType, NotSet
3
4
  from .frozen import Freezable, frozen
4
5
  from .singleton import Singleton
5
6
  from .enum import Enum
@@ -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)
@@ -0,0 +1,12 @@
1
+ from .singleton import Singleton
2
+
3
+
4
+ class NotSetType(Singleton):
5
+ """
6
+ A type that exists to denote a value has not been set
7
+ This might be useful when None is a valid value for a type
8
+ """
9
+
10
+
11
+ # The sole value for NotSetType
12
+ NotSet = NotSetType()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zstdlib
3
- Version: 0.0.4
3
+ Version: 0.0.6
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
@@ -2,6 +2,7 @@ LICENSE
2
2
  README.md
3
3
  pyproject.toml
4
4
  tests/__init__.py
5
+ tests/not_set.py
5
6
  tests/test_ansi.py
6
7
  tests/test_enum.py
7
8
  tests/test_frozen.py
@@ -14,6 +15,7 @@ zstdlib/__init__.py
14
15
  zstdlib/ansi.py
15
16
  zstdlib/enum.py
16
17
  zstdlib/frozen.py
18
+ zstdlib/not_set.py
17
19
  zstdlib/py.typed
18
20
  zstdlib/singleton.py
19
21
  zstdlib.egg-info/PKG-INFO
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