zstdlib 0.10.9__tar.gz → 0.10.10__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.
- {zstdlib-0.10.9 → zstdlib-0.10.10}/PKG-INFO +1 -1
- {zstdlib-0.10.9 → zstdlib-0.10.10}/pyproject.toml +1 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_singleton.py +1 -1
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/__init__.py +1 -1
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/singleton.py +9 -16
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib.egg-info/PKG-INFO +1 -1
- {zstdlib-0.10.9 → zstdlib-0.10.10}/LICENSE +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/README.md +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/setup.cfg +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/__init__.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/log/__init__.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/log/base.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/log/test_cute.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/log/test_trace.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_ansi.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_enum.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_exc_capture.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_frozen.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_hybridmethod.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_io.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_ip_lock.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_keyed_instance.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_lazy.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_not_set.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_prompt.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/tests/test_util.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/ansi.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/enum.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/exc_capture.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/frozen.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/hybridmethod.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/io.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/ip_lock.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/keyed_instance.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/lazy.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/log/__init__.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/log/cute.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/log/trace.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/macos.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/not_set.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/prompt.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/py.typed +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/signal_cm.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib/util.py +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib.egg-info/SOURCES.txt +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib.egg-info/dependency_links.txt +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib.egg-info/requires.txt +0 -0
- {zstdlib-0.10.9 → zstdlib-0.10.10}/zstdlib.egg-info/top_level.txt +0 -0
|
@@ -48,7 +48,7 @@ class TestSingleton(unittest.TestCase):
|
|
|
48
48
|
self.assertIs(ST.instance(), obj)
|
|
49
49
|
|
|
50
50
|
with self.assertRaises(TypeError):
|
|
51
|
-
ST.instance(4)
|
|
51
|
+
ST.instance(4)
|
|
52
52
|
|
|
53
53
|
def test_multi_thread(self) -> None:
|
|
54
54
|
"""Ensure that Singleton is thread safe and that constructing an object doesn't delay other threads
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import ClassVar, Never, Any
|
|
1
|
+
from typing import ClassVar, Never, Any, cast
|
|
2
2
|
from collections import defaultdict
|
|
3
3
|
from threading import RLock
|
|
4
4
|
from functools import cache
|
|
@@ -46,30 +46,23 @@ class _SingletonType(type):
|
|
|
46
46
|
ret = cls._instances[cls] = super().__call__(*args, **kwargs)
|
|
47
47
|
return ret
|
|
48
48
|
|
|
49
|
-
@classmethod
|
|
50
49
|
@cache
|
|
51
|
-
def instance(
|
|
50
|
+
def instance[T: Singleton](cls: type[T]) -> T:
|
|
52
51
|
"""Get the instance of cls"""
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
# pylint: disable=protected-access
|
|
53
|
+
mcs = cast(_SingletonType, type(cls)) # mypy can't figure this out :/
|
|
55
54
|
with mcs._lock:
|
|
56
|
-
cls_lock = mcs._cls_locks[
|
|
55
|
+
cls_lock = mcs._cls_locks[cls]
|
|
57
56
|
with cls_lock:
|
|
58
|
-
if (got := mcs._instances.get(
|
|
59
|
-
raise NoInstanceError(f"No instance of {
|
|
60
|
-
|
|
57
|
+
if (got := mcs._instances.get(cls, None)) is None:
|
|
58
|
+
raise NoInstanceError(f"No instance of {cls.__qualname__} found")
|
|
59
|
+
# pylint: enable=protected-access
|
|
60
|
+
return cast(T, got)
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
class Singleton(metaclass=_SingletonType):
|
|
64
64
|
"""A thread-safe singleton base class"""
|
|
65
65
|
|
|
66
|
-
@classmethod
|
|
67
|
-
def instance(cls) -> Singleton:
|
|
68
|
-
"""Blocking get the instance of cls; raise if not constructed"""
|
|
69
|
-
assert isinstance(cls, _SingletonType), "Metaclass should be _SingletonType"
|
|
70
|
-
tc: type[_SingletonType] = type(cls)
|
|
71
|
-
return tc.instance(cls)
|
|
72
|
-
|
|
73
66
|
def __init_subclass__(cls, *args: Any, **kwargs: Any) -> None:
|
|
74
67
|
"""Disallow subclassing"""
|
|
75
68
|
cls.__init_subclass__ = _no_subclass # type: ignore[method-assign]
|
|
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
|
|
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
|