zstdlib 0.8.0__tar.gz → 0.8.1__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.8.0 → zstdlib-0.8.1}/PKG-INFO +1 -1
- {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_lazy.py +16 -1
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/__init__.py +1 -1
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/lazy.py +12 -5
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib.egg-info/PKG-INFO +1 -1
- {zstdlib-0.8.0 → zstdlib-0.8.1}/LICENSE +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/README.md +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/pyproject.toml +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/setup.cfg +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/__init__.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/log/__init__.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/log/base.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/log/test_cute.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/log/test_trace.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_ansi.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_enum.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_frozen.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_io.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_not_set.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_singleton.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/ansi.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/enum.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/frozen.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/io.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/log/__init__.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/log/cute.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/log/trace.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/macos.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/not_set.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/py.typed +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/signal_cm.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/singleton.py +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib.egg-info/SOURCES.txt +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib.egg-info/dependency_links.txt +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib.egg-info/requires.txt +0 -0
- {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib.egg-info/top_level.txt +0 -0
|
@@ -11,12 +11,27 @@ def _append(buf: list[str], *, obj: str) -> str:
|
|
|
11
11
|
|
|
12
12
|
class TestLazy(unittest.TestCase):
|
|
13
13
|
|
|
14
|
+
def test_func(self) -> None:
|
|
15
|
+
buf: list[str] = []
|
|
16
|
+
obj = "apples"
|
|
17
|
+
x = Str(_append, buf, obj=obj)
|
|
18
|
+
self.assertEqual(buf, [])
|
|
19
|
+
# Invoke Lazy Func
|
|
20
|
+
one = x()
|
|
21
|
+
self.assertEqual(one, "1")
|
|
22
|
+
self.assertEqual(buf, [obj])
|
|
23
|
+
# Verify result was cached
|
|
24
|
+
also_one = x()
|
|
25
|
+
self.assertEqual(also_one, "1")
|
|
26
|
+
self.assertEqual(buf, [obj])
|
|
27
|
+
|
|
14
28
|
def test_str(self) -> None:
|
|
15
29
|
buf: list[str] = []
|
|
16
30
|
obj = "apples"
|
|
17
31
|
x = Str(_append, buf, obj=obj)
|
|
18
32
|
self.assertEqual(buf, [])
|
|
19
|
-
|
|
33
|
+
# Invoke Lazy Str
|
|
34
|
+
one = str(x)
|
|
20
35
|
self.assertEqual(one, "1")
|
|
21
36
|
self.assertEqual(buf, [obj])
|
|
22
37
|
|
|
@@ -4,16 +4,16 @@ from threading import Lock
|
|
|
4
4
|
|
|
5
5
|
P = ParamSpec("P")
|
|
6
6
|
|
|
7
|
-
__all__ = ("Str"
|
|
7
|
+
__all__ = ("Func", "Str")
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
class
|
|
11
|
-
"""A lazily evaluated
|
|
10
|
+
class Func:
|
|
11
|
+
"""A lazily evaluated function"""
|
|
12
12
|
|
|
13
13
|
__slots__ = ("_args", "_fn", "_kwargs", "_lock", "_result")
|
|
14
14
|
|
|
15
15
|
def __init__(self, fn: Callable[P, str], *args: P.args, **kwargs: P.kwargs) -> None:
|
|
16
|
-
"""Store a function and its arguments, on
|
|
16
|
+
"""Store a function and its arguments, on __call__(self) return fn(*args, **kwargs)
|
|
17
17
|
The result of the function invocation is cached and will be reused
|
|
18
18
|
"""
|
|
19
19
|
self._result: str | None = None
|
|
@@ -22,10 +22,17 @@ class Str:
|
|
|
22
22
|
self._args = args
|
|
23
23
|
self._kwargs = kwargs
|
|
24
24
|
|
|
25
|
-
def
|
|
25
|
+
def __call__(self) -> str:
|
|
26
26
|
"""Evaluate the saved function"""
|
|
27
27
|
if self._result is not None:
|
|
28
28
|
return self._result
|
|
29
29
|
with self._lock:
|
|
30
30
|
self._result = self._fn(*self._args, **self._kwargs)
|
|
31
31
|
return self._result
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Str(Func):
|
|
35
|
+
"""A lazily evaluated string"""
|
|
36
|
+
|
|
37
|
+
def __str__(self) -> str:
|
|
38
|
+
return self()
|
|
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
|