zstdlib 0.10.12__tar.gz → 0.10.14__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 (52) hide show
  1. {zstdlib-0.10.12 → zstdlib-0.10.14}/PKG-INFO +1 -1
  2. zstdlib-0.10.14/tests/test_hybridmethod.py +94 -0
  3. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/__init__.py +3 -5
  4. zstdlib-0.10.14/zstdlib/exc/__init__.py +5 -0
  5. zstdlib-0.10.12/zstdlib/exc_capture.py → zstdlib-0.10.14/zstdlib/exc/capture.py +4 -4
  6. zstdlib-0.10.14/zstdlib/exc/pop_frames.py +79 -0
  7. zstdlib-0.10.14/zstdlib/exc/raise_.py +26 -0
  8. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/hybridmethod.py +17 -2
  9. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib.egg-info/PKG-INFO +1 -1
  10. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib.egg-info/SOURCES.txt +4 -2
  11. zstdlib-0.10.12/tests/test_exc_capture.py +0 -96
  12. zstdlib-0.10.12/tests/test_hybridmethod.py +0 -37
  13. {zstdlib-0.10.12 → zstdlib-0.10.14}/LICENSE +0 -0
  14. {zstdlib-0.10.12 → zstdlib-0.10.14}/README.md +0 -0
  15. {zstdlib-0.10.12 → zstdlib-0.10.14}/pyproject.toml +0 -0
  16. {zstdlib-0.10.12 → zstdlib-0.10.14}/setup.cfg +0 -0
  17. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/__init__.py +0 -0
  18. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/log/__init__.py +0 -0
  19. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/log/base.py +0 -0
  20. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/log/test_cute.py +0 -0
  21. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/log/test_trace.py +0 -0
  22. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/test_ansi.py +0 -0
  23. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/test_enum.py +0 -0
  24. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/test_frozen.py +0 -0
  25. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/test_io.py +0 -0
  26. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/test_ip_lock.py +0 -0
  27. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/test_keyed_instance.py +0 -0
  28. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/test_lazy.py +0 -0
  29. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/test_not_set.py +0 -0
  30. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/test_prompt.py +0 -0
  31. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/test_singleton.py +0 -0
  32. {zstdlib-0.10.12 → zstdlib-0.10.14}/tests/test_util.py +0 -0
  33. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/ansi.py +0 -0
  34. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/enum.py +0 -0
  35. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/frozen.py +0 -0
  36. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/io.py +0 -0
  37. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/ip_lock.py +0 -0
  38. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/keyed_instance.py +0 -0
  39. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/lazy.py +0 -0
  40. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/log/__init__.py +0 -0
  41. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/log/cute.py +0 -0
  42. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/log/trace.py +0 -0
  43. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/macos.py +0 -0
  44. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/not_set.py +0 -0
  45. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/prompt.py +0 -0
  46. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/py.typed +0 -0
  47. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/signal_cm.py +0 -0
  48. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/singleton.py +0 -0
  49. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib/util.py +0 -0
  50. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib.egg-info/dependency_links.txt +0 -0
  51. {zstdlib-0.10.12 → zstdlib-0.10.14}/zstdlib.egg-info/requires.txt +0 -0
  52. {zstdlib-0.10.12 → zstdlib-0.10.14}/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.14
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,8 +1,7 @@
1
- __version__ = "0.10.12"
1
+ __version__ = "0.10.14"
2
2
 
3
3
  from .prompt import prompt_until, prompt_for, yn_prompt
4
4
  from .ip_lock import GlobalIPLock, IPLock, RIPLock
5
- from .exc_capture import ExcCapture, ExcDelay
6
5
  from .keyed_instance import KeyedInstance
7
6
  from .hybridmethod import hybridmethod
8
7
  from .not_set import NotSetType, NotSet
@@ -11,12 +10,10 @@ from .singleton import Singleton
11
10
  from .signal_cm import signal_cm
12
11
  from .enum import Enum, auto
13
12
  from .util import normpath
14
- from . import macos, lazy, log, io
13
+ from . import macos, lazy, log, exc, io
15
14
 
16
15
  __all__ = (
17
16
  "Enum",
18
- "ExcCapture",
19
- "ExcDelay",
20
17
  "Freezable",
21
18
  "GlobalIPLock",
22
19
  "IPLock",
@@ -26,6 +23,7 @@ __all__ = (
26
23
  "RIPLock",
27
24
  "Singleton",
28
25
  "auto",
26
+ "exc",
29
27
  "frozen",
30
28
  "hybridmethod",
31
29
  "io",
@@ -0,0 +1,5 @@
1
+ from .capture import Capture, Delay
2
+ from .pop_frames import PopFrames
3
+ from .raise_ import raise_
4
+
5
+ __all__ = ("Capture", "Delay", "PopFrames", "raise_")
@@ -2,13 +2,13 @@ from contextlib import AbstractContextManager, contextmanager
2
2
  from collections.abc import Callable, Iterator
3
3
  from typing import Self
4
4
 
5
- __all__ = ("ExcCapture", "ExcDelay")
5
+ __all__ = ("Capture", "Delay")
6
6
 
7
7
 
8
8
  type EXC_T = type[BaseException] | tuple[type[BaseException]]
9
9
 
10
10
 
11
- class ExcCapture:
11
+ class Capture:
12
12
  """A class that exposes a context manager which captures and suppresses any raised exception of a given type / tuple of types"""
13
13
 
14
14
  # In python3.15 use sentinel
@@ -62,8 +62,8 @@ class ExcCapture:
62
62
  return self.NoResult
63
63
 
64
64
 
65
- class ExcDelay(ExcCapture):
66
- """A context manager subclass of ExcCapture that raises on exit if errors are captured"""
65
+ class Delay(Capture):
66
+ """A context manager subclass of Capture that raises on exit if errors are captured"""
67
67
 
68
68
  __slots__ = ("_msg", "armed")
69
69
 
@@ -0,0 +1,79 @@
1
+ from types import TracebackType
2
+ from typing import Self
3
+ import sys
4
+
5
+ __all__ = ("PopFrames",)
6
+
7
+
8
+ class PopFrames:
9
+ """
10
+ A context manager used to pop traceback frames from an exception;
11
+ Note that python traceback frames are added as each call exception propgation unwinds the call stack
12
+ Thus you can only pop frames between the frame PopFrames lives in and where the exceptions was raised
13
+ MRO superclasses are not supported
14
+ """
15
+
16
+ __slots__ = ("_furthest_n", "_n")
17
+
18
+ def __init__(self, n: int = 0, *, furthest_n: int = 0) -> None:
19
+ self._validate(n, furthest_n)
20
+ self._furthest_n: int = furthest_n
21
+ self._n = n
22
+
23
+ def __enter__(self) -> Self:
24
+ return self
25
+
26
+ def __exit__(
27
+ self, _: type[BaseException] | None, exc: BaseException | None, _2: TracebackType | None
28
+ ) -> None:
29
+ if isinstance(exc, BaseException):
30
+ self.modify(exc, self._n, furthest_n=self._furthest_n)
31
+ elif exc is not None:
32
+ raise TypeError("exc is not a BaseException | None")
33
+
34
+ @classmethod
35
+ def modify(cls, exc: BaseException, n: int, furthest_n: int = 0) -> None:
36
+ """Modify the traceback frames of exc; removes the n most recently entered frames
37
+ If foo calls bar calls baz which raises, n=2 removes (baz, raise)
38
+ from the traceback and furthest_n=1 removes foo from the traceback
39
+
40
+ Args:
41
+ exc: The exception to modify
42
+ n: The number of frames to remove, referse to the most recently entered frames
43
+ furthest_n: The number of frames to remove, referse to the least recently entered frames
44
+ """
45
+ cls._validate(n, furthest_n)
46
+ if not isinstance(exc, BaseException):
47
+ raise TypeError("exc is not a BaseException")
48
+ if n == furthest_n == 0:
49
+ return
50
+ # Record the old traceback
51
+ frames: list[TracebackType] = []
52
+ tb = exc.__traceback__
53
+ while tb is not None:
54
+ frames.append(tb)
55
+ tb = tb.tb_next
56
+ # Install the new traceback
57
+ new: TracebackType | None = None
58
+ for f in reversed(frames[furthest_n if furthest_n else None : -n if n else None]):
59
+ new = TracebackType(new, f.tb_frame, f.tb_lasti, f.tb_lineno)
60
+ exc.__traceback__ = new
61
+
62
+ @classmethod
63
+ def active(cls, n: int = 0, *, reraise: bool, furthest_n: int = 0) -> None:
64
+ """Remove traceback frames from an active exception, will reraise unless False"""
65
+ e = sys.exc_info()
66
+ if e[0] is None:
67
+ raise RuntimeError("No active exception")
68
+ cls.modify(e[1], n, furthest_n=furthest_n)
69
+ if reraise:
70
+ raise # noqa: PLE0704 # pylint: disable=misplaced-bare-raise
71
+
72
+ # Private helpers
73
+
74
+ @staticmethod
75
+ def _validate(n: int, furthest_n: int) -> None:
76
+ if not isinstance(n, int) or not isinstance(furthest_n, int):
77
+ raise TypeError("Number of frames to pop must be type int")
78
+ if n < 0 or furthest_n < 0:
79
+ raise ValueError("May not pop a negative number of frames")
@@ -0,0 +1,26 @@
1
+ from collections.abc import Callable
2
+ from typing import Never
3
+
4
+ from ..not_set import NotSetType, NotSet
5
+ from .pop_frames import PopFrames
6
+
7
+ __all__ = ("raise_",)
8
+
9
+
10
+ def raise_[**P, R: BaseException](
11
+ e: BaseException,
12
+ from_: Callable[P, R] | R | None | NotSetType = NotSet,
13
+ /,
14
+ *args: P.args,
15
+ **kwargs: P.kwargs,
16
+ ) -> Never:
17
+ """Raise e from from_; if from_ isn't an exception, from_=from_(*args, **kwargs)"""
18
+ if not isinstance(from_, BaseException | None | NotSetType):
19
+ if not callable(from_):
20
+ raise TypeError("from_ must be callable")
21
+ from_ = from_(*args, **kwargs)
22
+ with PopFrames(1):
23
+ if from_ is NotSet:
24
+ raise e
25
+ assert isinstance(from_, BaseException | None)
26
+ raise e from from_
@@ -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.14
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
@@ -4,7 +4,6 @@ pyproject.toml
4
4
  tests/__init__.py
5
5
  tests/test_ansi.py
6
6
  tests/test_enum.py
7
- tests/test_exc_capture.py
8
7
  tests/test_frozen.py
9
8
  tests/test_hybridmethod.py
10
9
  tests/test_io.py
@@ -22,7 +21,6 @@ tests/log/test_trace.py
22
21
  zstdlib/__init__.py
23
22
  zstdlib/ansi.py
24
23
  zstdlib/enum.py
25
- zstdlib/exc_capture.py
26
24
  zstdlib/frozen.py
27
25
  zstdlib/hybridmethod.py
28
26
  zstdlib/io.py
@@ -41,6 +39,10 @@ zstdlib.egg-info/SOURCES.txt
41
39
  zstdlib.egg-info/dependency_links.txt
42
40
  zstdlib.egg-info/requires.txt
43
41
  zstdlib.egg-info/top_level.txt
42
+ zstdlib/exc/__init__.py
43
+ zstdlib/exc/capture.py
44
+ zstdlib/exc/pop_frames.py
45
+ zstdlib/exc/raise_.py
44
46
  zstdlib/log/__init__.py
45
47
  zstdlib/log/cute.py
46
48
  zstdlib/log/trace.py
@@ -1,96 +0,0 @@
1
- # pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
2
- import unittest
3
-
4
- from zstdlib import ExcCapture, ExcDelay
5
-
6
-
7
- class TestLazy(unittest.TestCase):
8
-
9
- def test_capture(self) -> None:
10
- # Capture nothing
11
- rt = ExcCapture(RuntimeError)
12
- with rt.capture():
13
- pass
14
- self.assertEqual(len(rt.errors), 0)
15
- # Capture only Runtime
16
- with rt.capture():
17
- raise RuntimeError()
18
- self.assertEqual(len(rt.errors), 1)
19
- with self.assertRaises(ValueError), rt.capture():
20
- raise ValueError()
21
- self.assertEqual(len(rt.errors), 1)
22
- # previous
23
- with rt.capture():
24
- pass
25
- self.assertIs(rt.previous, None)
26
- test_err = RuntimeError("test")
27
- with rt.capture():
28
- raise test_err
29
- self.assertEqual(rt.previous, test_err)
30
- # capture's exc_t
31
- rt = ExcCapture(RuntimeError)
32
- with self.assertRaises(RuntimeError), rt.capture(ValueError):
33
- raise RuntimeError()
34
- self.assertEqual(len(rt.errors), 0)
35
- with rt.capture(ValueError):
36
- raise ValueError()
37
- self.assertEqual(len(rt.errors), 1)
38
- del rt
39
- # exc_t = None
40
- non = ExcCapture()
41
- with self.assertRaises(RuntimeError), non.capture(ValueError):
42
- raise RuntimeError()
43
- self.assertEqual(len(non.errors), 0)
44
- with self.assertRaises(ValueError), non.capture():
45
- pass
46
- self.assertEqual(len(non.errors), 0)
47
- with non.capture(RuntimeError):
48
- raise RuntimeError()
49
- self.assertEqual(len(non.errors), 1)
50
- # run_fn
51
- ke = ExcCapture(KeyError)
52
- self.assertEqual(ke.run_fn({0: 5}.__getitem__, 0), 5)
53
- self.assertEqual(len(ke.errors), 0)
54
- self.assertIs(ke.run_fn({}.__getitem__, 0), ke.NoResult)
55
- self.assertEqual(len(ke.errors), 1)
56
-
57
- def test_delay(self) -> None:
58
- # No raise
59
- with ExcDelay("msg", RuntimeError) as capture, capture():
60
- pass
61
- # Raise
62
- ed = ExcDelay("msg", RuntimeError)
63
- try:
64
- with ed as capture:
65
- with capture():
66
- raise RuntimeError()
67
- with capture():
68
- raise RuntimeError()
69
- self.assertTrue(False)
70
- except BaseExceptionGroup as grp:
71
- self.assertIsInstance(grp, ExceptionGroup) # Test auto-conversion
72
- self.assertEqual(len(grp.exceptions), 2)
73
- self.assertEqual(len(ed.errors), 2)
74
- # No block error
75
- with self.assertRaises(ValueError), ExcDelay("msg", RuntimeError) as capture, capture():
76
- raise ValueError()
77
- with self.assertRaises(ValueError), ExcDelay("msg", RuntimeError) as capture:
78
- with capture():
79
- raise RuntimeError()
80
- raise ValueError()
81
- # msg
82
- _ = ExcDelay("")
83
- with self.assertRaises(TypeError):
84
- ExcDelay(RuntimeError) # type: ignore[arg-type]
85
- # armed
86
- with ExcDelay("", RuntimeError, armed=False) as capture, capture():
87
- raise RuntimeError()
88
- with ExcDelay("", RuntimeError, armed=True) as capture, capture():
89
- capture.armed = False
90
- raise RuntimeError()
91
- with self.assertRaises(ExceptionGroup), ExcDelay("", RuntimeError, armed=True) as capture, capture():
92
- raise RuntimeError()
93
-
94
-
95
- if __name__ == "__main__":
96
- unittest.main()
@@ -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