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.
Files changed (36) hide show
  1. {zstdlib-0.8.0 → zstdlib-0.8.1}/PKG-INFO +1 -1
  2. {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_lazy.py +16 -1
  3. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/__init__.py +1 -1
  4. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/lazy.py +12 -5
  5. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib.egg-info/PKG-INFO +1 -1
  6. {zstdlib-0.8.0 → zstdlib-0.8.1}/LICENSE +0 -0
  7. {zstdlib-0.8.0 → zstdlib-0.8.1}/README.md +0 -0
  8. {zstdlib-0.8.0 → zstdlib-0.8.1}/pyproject.toml +0 -0
  9. {zstdlib-0.8.0 → zstdlib-0.8.1}/setup.cfg +0 -0
  10. {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/__init__.py +0 -0
  11. {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/log/__init__.py +0 -0
  12. {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/log/base.py +0 -0
  13. {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/log/test_cute.py +0 -0
  14. {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/log/test_trace.py +0 -0
  15. {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_ansi.py +0 -0
  16. {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_enum.py +0 -0
  17. {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_frozen.py +0 -0
  18. {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_io.py +0 -0
  19. {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_not_set.py +0 -0
  20. {zstdlib-0.8.0 → zstdlib-0.8.1}/tests/test_singleton.py +0 -0
  21. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/ansi.py +0 -0
  22. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/enum.py +0 -0
  23. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/frozen.py +0 -0
  24. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/io.py +0 -0
  25. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/log/__init__.py +0 -0
  26. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/log/cute.py +0 -0
  27. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/log/trace.py +0 -0
  28. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/macos.py +0 -0
  29. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/not_set.py +0 -0
  30. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/py.typed +0 -0
  31. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/signal_cm.py +0 -0
  32. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib/singleton.py +0 -0
  33. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib.egg-info/SOURCES.txt +0 -0
  34. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib.egg-info/dependency_links.txt +0 -0
  35. {zstdlib-0.8.0 → zstdlib-0.8.1}/zstdlib.egg-info/requires.txt +0 -0
  36. {zstdlib-0.8.0 → zstdlib-0.8.1}/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.8.0
3
+ Version: 0.8.1
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
@@ -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
- one = str(x) # Invoke Lazy Str
33
+ # Invoke Lazy Str
34
+ one = str(x)
20
35
  self.assertEqual(one, "1")
21
36
  self.assertEqual(buf, [obj])
22
37
 
@@ -1,4 +1,4 @@
1
- __version__ = "0.8.0"
1
+ __version__ = "0.8.1"
2
2
 
3
3
  from .not_set import NotSetType, NotSet
4
4
  from .frozen import Freezable, frozen
@@ -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 Str:
11
- """A lazily evaluated string class"""
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 str(self) return fn(*args, **kwargs)
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 __str__(self) -> str:
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zstdlib
3
- Version: 0.8.0
3
+ Version: 0.8.1
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
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