zstdlib 0.10.12__tar.gz → 0.10.13__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 (49) hide show
  1. {zstdlib-0.10.12 → zstdlib-0.10.13}/PKG-INFO +1 -1
  2. zstdlib-0.10.13/tests/test_hybridmethod.py +94 -0
  3. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/__init__.py +1 -1
  4. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/hybridmethod.py +17 -2
  5. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib.egg-info/PKG-INFO +1 -1
  6. zstdlib-0.10.12/tests/test_hybridmethod.py +0 -37
  7. {zstdlib-0.10.12 → zstdlib-0.10.13}/LICENSE +0 -0
  8. {zstdlib-0.10.12 → zstdlib-0.10.13}/README.md +0 -0
  9. {zstdlib-0.10.12 → zstdlib-0.10.13}/pyproject.toml +0 -0
  10. {zstdlib-0.10.12 → zstdlib-0.10.13}/setup.cfg +0 -0
  11. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/__init__.py +0 -0
  12. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/log/__init__.py +0 -0
  13. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/log/base.py +0 -0
  14. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/log/test_cute.py +0 -0
  15. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/log/test_trace.py +0 -0
  16. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/test_ansi.py +0 -0
  17. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/test_enum.py +0 -0
  18. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/test_exc_capture.py +0 -0
  19. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/test_frozen.py +0 -0
  20. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/test_io.py +0 -0
  21. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/test_ip_lock.py +0 -0
  22. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/test_keyed_instance.py +0 -0
  23. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/test_lazy.py +0 -0
  24. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/test_not_set.py +0 -0
  25. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/test_prompt.py +0 -0
  26. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/test_singleton.py +0 -0
  27. {zstdlib-0.10.12 → zstdlib-0.10.13}/tests/test_util.py +0 -0
  28. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/ansi.py +0 -0
  29. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/enum.py +0 -0
  30. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/exc_capture.py +0 -0
  31. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/frozen.py +0 -0
  32. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/io.py +0 -0
  33. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/ip_lock.py +0 -0
  34. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/keyed_instance.py +0 -0
  35. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/lazy.py +0 -0
  36. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/log/__init__.py +0 -0
  37. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/log/cute.py +0 -0
  38. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/log/trace.py +0 -0
  39. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/macos.py +0 -0
  40. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/not_set.py +0 -0
  41. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/prompt.py +0 -0
  42. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/py.typed +0 -0
  43. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/signal_cm.py +0 -0
  44. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/singleton.py +0 -0
  45. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib/util.py +0 -0
  46. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib.egg-info/SOURCES.txt +0 -0
  47. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib.egg-info/dependency_links.txt +0 -0
  48. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib.egg-info/requires.txt +0 -0
  49. {zstdlib-0.10.12 → zstdlib-0.10.13}/zstdlib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zstdlib
3
- Version: 0.10.12
3
+ Version: 0.10.13
4
4
  Summary: A set of useful python utilities
5
5
  License-Expression: GPL-3.0-only
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
@@ -0,0 +1,94 @@
1
+ # pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring,unused-variable
2
+ from typing import ClassVar
3
+ import unittest
4
+
5
+ from zstdlib import hybridmethod
6
+
7
+
8
+ class TestHybridMethod(unittest.TestCase):
9
+
10
+ def test_hybridmethod(self) -> None:
11
+
12
+ class A:
13
+ objs: ClassVar[dict[int, A]] = {}
14
+
15
+ def __init__(self, x: int) -> None:
16
+ self.x: int = x
17
+ self.objs[x] = self
18
+
19
+ @hybridmethod
20
+ def get(self: A | None, cls: type[A], *, x: int | None = None) -> A:
21
+ if x is not None:
22
+ return cls.objs[x]
23
+ if self is None:
24
+ raise TypeError("Unable to determine x")
25
+ return cls.objs[self.x]
26
+
27
+ a = A(1)
28
+ b = A(2)
29
+ self.assertIsNot(a, b)
30
+ self.assertIs(a.get(), a)
31
+ self.assertIs(A.get(x=2), b)
32
+ with self.assertRaises(TypeError):
33
+ A.get()
34
+
35
+ def test_metadata(self) -> None:
36
+
37
+ class A:
38
+
39
+ @hybridmethod
40
+ def foo(self: A | None, cls: type[A]) -> None:
41
+ """hi"""
42
+
43
+ foo2 = foo
44
+
45
+ @staticmethod
46
+ def bar(self: A | None, cls: type[A]) -> None: # noqa: PLW0211
47
+ """hi2"""
48
+
49
+ baz = hybridmethod(bar)
50
+ baz2 = baz
51
+
52
+ a = A()
53
+ self.assertEqual(A.foo.__doc__, "hi")
54
+ self.assertEqual(a.foo.__doc__, "hi")
55
+ self.assertEqual(A.bar.__doc__, "hi2")
56
+ self.assertEqual(a.bar.__doc__, "hi2")
57
+ self.assertEqual(A.baz.__doc__, "hi2")
58
+ self.assertEqual(a.baz.__doc__, "hi2")
59
+
60
+ def qn_a(x: str) -> str:
61
+ return f"{self.__class__.__qualname__}.test_metadata.<locals>.A.{x}"
62
+
63
+ self.assertEqual(A.foo.__name__, "foo")
64
+ self.assertEqual(a.foo.__name__, "foo")
65
+ self.assertEqual(A.foo.__qualname__, qn_a("foo"))
66
+ self.assertEqual(a.foo.__qualname__, qn_a("foo"))
67
+
68
+ self.assertEqual(A.foo2.__name__, "foo")
69
+ self.assertEqual(a.foo2.__name__, "foo")
70
+ self.assertEqual(A.foo2.__qualname__, qn_a("foo"))
71
+ self.assertEqual(a.foo2.__qualname__, qn_a("foo"))
72
+
73
+ self.assertEqual(A.bar.__name__, "bar")
74
+ self.assertEqual(a.bar.__name__, "bar")
75
+ self.assertEqual(A.bar.__qualname__, qn_a("bar"))
76
+ self.assertEqual(a.bar.__qualname__, qn_a("bar"))
77
+
78
+ self.assertEqual(A.baz.__name__, "baz")
79
+ self.assertEqual(a.baz.__name__, "baz")
80
+ self.assertEqual(A.baz.__qualname__, qn_a("baz"))
81
+ self.assertEqual(a.baz.__qualname__, qn_a("baz"))
82
+
83
+ self.assertEqual(A.baz2.__name__, "baz")
84
+
85
+ class B(A):
86
+ pass
87
+
88
+ b = B()
89
+ self.assertEqual(B.baz.__name__, "baz")
90
+ self.assertEqual(b.baz.__name__, "baz")
91
+
92
+
93
+ if __name__ == "__main__":
94
+ unittest.main()
@@ -1,4 +1,4 @@
1
- __version__ = "0.10.12"
1
+ __version__ = "0.10.13"
2
2
 
3
3
  from .prompt import prompt_until, prompt_for, yn_prompt
4
4
  from .ip_lock import GlobalIPLock, IPLock, RIPLock
@@ -1,4 +1,4 @@
1
- from typing import Concatenate, overload
1
+ from typing import Concatenate, overload, final
2
2
  from collections.abc import Callable
3
3
  from functools import wraps
4
4
 
@@ -8,6 +8,7 @@ __all__ = ("hybridmethod",)
8
8
  type _HybridFunc[T, R, **P] = Callable[Concatenate[T | None, type[T], P], R]
9
9
 
10
10
 
11
+ @final
11
12
  class hybridmethod[T, R, **P]: # Name aligns with @staticmethod and such
12
13
  """
13
14
  A member function decorator that combines an instances bound function and @classmethod
@@ -21,12 +22,21 @@ class hybridmethod[T, R, **P]: # Name aligns with @staticmethod and such
21
22
  A.history(id=0)
22
23
  a.history()
23
24
  Note that using Self is the type signature is invalid, just as it is with @classmethod
25
+ Also due to a mypy limitations, it might be useful to initially define f as @staticmethod _f
26
+ Then to do f = hybridmethod(_f) afterwards (documentation will try to automatically update for you)
24
27
  """
25
28
 
26
- __slots__ = ("_fn",)
29
+ __slots__ = ("_fn", "_name", "_qualname")
27
30
 
28
31
  def __init__(self, fn: _HybridFunc[T, R, P]) -> None:
29
32
  self._fn: _HybridFunc[T, R, P] = fn
33
+ self._qualname: str | None = None
34
+ self._name: str | None = None
35
+
36
+ def __set_name__(self, owner: type[T], name: str) -> None:
37
+ if self._name is None:
38
+ self._qualname = f"{owner.__qualname__}.{name}"
39
+ self._name = name
30
40
 
31
41
  @overload
32
42
  def __get__(self, instance: T, owner: type[T] | None = None, /) -> Callable[P, R]: ...
@@ -45,4 +55,9 @@ class hybridmethod[T, R, **P]: # Name aligns with @staticmethod and such
45
55
  def ret(*args: P.args, **kwargs: P.kwargs) -> R:
46
56
  return self._fn(instance, owner, *args, **kwargs)
47
57
 
58
+ if self._name is not None:
59
+ ret.__name__ = self._name
60
+ assert self._qualname is not None
61
+ ret.__qualname__ = self._qualname
62
+
48
63
  return ret
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zstdlib
3
- Version: 0.10.12
3
+ Version: 0.10.13
4
4
  Summary: A set of useful python utilities
5
5
  License-Expression: GPL-3.0-only
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
@@ -1,37 +0,0 @@
1
- # pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring,unused-variable
2
- from typing import ClassVar
3
- import unittest
4
-
5
- from zstdlib import hybridmethod
6
-
7
-
8
- class TestHybridMethod(unittest.TestCase):
9
-
10
- def test_hybridmethod(self) -> None:
11
-
12
- class A:
13
- objs: ClassVar[dict[int, A]] = {}
14
-
15
- def __init__(self, x: int) -> None:
16
- self.x: int = x
17
- self.objs[x] = self
18
-
19
- @hybridmethod
20
- def get(self: A | None, cls: type[A], *, x: int | None = None) -> A:
21
- if x is not None:
22
- return cls.objs[x]
23
- if self is None:
24
- raise TypeError("Unable to determine x")
25
- return cls.objs[self.x]
26
-
27
- a = A(1)
28
- b = A(2)
29
- self.assertIsNot(a, b)
30
- self.assertIs(a.get(), a)
31
- self.assertIs(A.get(x=2), b)
32
- with self.assertRaises(TypeError):
33
- A.get()
34
-
35
-
36
- if __name__ == "__main__":
37
- unittest.main()
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
File without changes
File without changes
File without changes
File without changes