zstdlib 0.10.3__tar.gz → 0.10.5__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 (40) hide show
  1. {zstdlib-0.10.3 → zstdlib-0.10.5}/PKG-INFO +1 -1
  2. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/log/test_trace.py +4 -4
  3. zstdlib-0.10.5/tests/test_hybridmethod.py +37 -0
  4. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/__init__.py +3 -1
  5. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/enum.py +1 -1
  6. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/frozen.py +1 -1
  7. zstdlib-0.10.5/zstdlib/hybridmethod.py +45 -0
  8. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/io.py +0 -2
  9. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/log/cute.py +1 -1
  10. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/macos.py +11 -12
  11. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib.egg-info/PKG-INFO +1 -1
  12. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib.egg-info/SOURCES.txt +2 -0
  13. {zstdlib-0.10.3 → zstdlib-0.10.5}/LICENSE +0 -0
  14. {zstdlib-0.10.3 → zstdlib-0.10.5}/README.md +0 -0
  15. {zstdlib-0.10.3 → zstdlib-0.10.5}/pyproject.toml +0 -0
  16. {zstdlib-0.10.3 → zstdlib-0.10.5}/setup.cfg +0 -0
  17. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/__init__.py +0 -0
  18. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/log/__init__.py +0 -0
  19. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/log/base.py +0 -0
  20. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/log/test_cute.py +0 -0
  21. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/test_ansi.py +0 -0
  22. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/test_enum.py +0 -0
  23. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/test_exc_capture.py +0 -0
  24. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/test_frozen.py +0 -0
  25. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/test_io.py +0 -0
  26. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/test_lazy.py +0 -0
  27. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/test_not_set.py +0 -0
  28. {zstdlib-0.10.3 → zstdlib-0.10.5}/tests/test_singleton.py +0 -0
  29. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/ansi.py +0 -0
  30. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/exc_capture.py +0 -0
  31. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/lazy.py +0 -0
  32. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/log/__init__.py +0 -0
  33. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/log/trace.py +0 -0
  34. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/not_set.py +0 -0
  35. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/py.typed +0 -0
  36. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/signal_cm.py +0 -0
  37. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib/singleton.py +0 -0
  38. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib.egg-info/dependency_links.txt +0 -0
  39. {zstdlib-0.10.3 → zstdlib-0.10.5}/zstdlib.egg-info/requires.txt +0 -0
  40. {zstdlib-0.10.3 → zstdlib-0.10.5}/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.3
3
+ Version: 0.10.5
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
@@ -46,20 +46,20 @@ class TestTrace(LeftBase, unittest.TestCase):
46
46
  # Root check
47
47
  with self.hijack("") as log:
48
48
  old = log.getEffectiveLevel()
49
- # pylint: disable=not-callable
49
+ # pylint: disable-next=not-callable
50
50
  logging.trace("test1") # type: ignore[misc]
51
51
  log.setLevel(logging.DEBUG)
52
- # pylint: disable=not-callable
52
+ # pylint: disable-next=not-callable
53
53
  logging.trace("test2") # type: ignore[misc]
54
54
  log.setLevel(old)
55
55
  self.assertEqual(self.messages[log], ["test1"])
56
56
  # Logger check
57
57
  with self.hijack("TestTrace.t1") as log:
58
58
  old = log.getEffectiveLevel()
59
- # pylint: disable=not-callable
59
+ # pylint: disable-next=not-callable
60
60
  log.trace("test3")
61
61
  log.setLevel(logging.DEBUG)
62
- # pylint: disable=not-callable
62
+ # pylint: disable-next=not-callable
63
63
  log.trace("test4")
64
64
  log.setLevel(old)
65
65
  self.assertEqual(self.messages[log], ["test3"])
@@ -0,0 +1,37 @@
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()
@@ -1,6 +1,7 @@
1
- __version__ = "0.10.3"
1
+ __version__ = "0.10.5"
2
2
 
3
3
  from .exc_capture import ExcCapture, ExcDelay
4
+ from .hybridmethod import hybridmethod
4
5
  from .not_set import NotSetType, NotSet
5
6
  from .frozen import Freezable, frozen
6
7
  from .singleton import Singleton
@@ -18,6 +19,7 @@ __all__ = (
18
19
  "Singleton",
19
20
  "auto",
20
21
  "frozen",
22
+ "hybridmethod",
21
23
  "io",
22
24
  "lazy",
23
25
  "log",
@@ -76,7 +76,7 @@ class EnumType(type):
76
76
  raise ValueError("Non-auto enum entries must be type annotated") from None
77
77
  return ret
78
78
 
79
- # pylint: disable=too-many-arguments, dangerous-default-value, too-many-locals
79
+ # pylint: disable-next=too-many-arguments, dangerous-default-value, too-many-locals
80
80
  def __new__(
81
81
  mcs: type[EnumType],
82
82
  name: str,
@@ -88,7 +88,7 @@ def frozen[T](arg: str | type[T]) -> Callable[[type[T]], type[T]] | type[T]:
88
88
 
89
89
  def new_method(self: Any, *args: Any, **kwargs: Any) -> Any:
90
90
  ret = original_method(self, *args, **kwargs)
91
- # pylint: disable=protected-access
91
+ # pylint: disable-next=protected-access
92
92
  self._freezable_frozen_ = True # type: ignore[attr-defined]
93
93
  return ret
94
94
 
@@ -0,0 +1,45 @@
1
+ from typing import Concatenate, overload
2
+ from collections.abc import Callable
3
+
4
+ __all__ = ("hybridmethod",)
5
+
6
+
7
+ type _HybridFunc[T, R, **P] = Callable[Concatenate[T | None, type[T], P], R]
8
+
9
+
10
+ class hybridmethod[T, R, **P]: # Name aligns with @staticmethod and such
11
+ """
12
+ A member function decorator that combines an instances bound function and @classmethod
13
+ If a member function uses @hybridmethod then it may use the signature:
14
+ @hybridmethod
15
+ def f(self: Self | None, cls: type[Self], ...)
16
+ This could be used to implement functions such as:
17
+ def history(self: Self | None, cls: type[Self], *, id: int | None = None): ...
18
+ ...
19
+ A.history(id=a.id)
20
+ A.history(id=0)
21
+ a.history()
22
+ """
23
+
24
+ __slots__ = ("_fn",)
25
+
26
+ def __init__(self, fn: _HybridFunc[T, R, P]) -> None:
27
+ self._fn: _HybridFunc[T, R, P] = fn
28
+
29
+ @overload
30
+ def __get__(self, instance: T, owner: type[T] | None = None, /) -> Callable[P, R]: ...
31
+
32
+ @overload
33
+ def __get__(self, instance: None, owner: type[T], /) -> Callable[P, R]: ...
34
+
35
+ def __get__(self, instance: T | None, owner: type[T] | None = None, /) -> Callable[P, R]:
36
+ if owner is None:
37
+ if instance is None:
38
+ raise TypeError("instance and owner should not both be None")
39
+ owner = type(instance)
40
+
41
+ # functools.partial doesn't preserve typing as we need it to :/
42
+ def ret(*args: P.args, **kwargs: P.kwargs) -> R:
43
+ return self._fn(instance, owner, *args, **kwargs)
44
+
45
+ return ret
@@ -32,8 +32,6 @@ class ProtectedFile:
32
32
  return hash(self.raw)
33
33
 
34
34
 
35
- # See bug: https://github.com/pylint-dev/pylint/issues/9335
36
- # pylint: disable=undefined-variable
37
35
  class _IOWrapperBase[T: (str, bytes)]:
38
36
  """A base class for IO objects that adds additional functionality such as readuntil, unread, and peek
39
37
  These classes are singletons with respect to their input object
@@ -22,7 +22,7 @@ class CuteFormatter(Formatter):
22
22
  CRITICAL: Color.bright_red_bg_yellow,
23
23
  }
24
24
 
25
- # pylint: disable=dangerous-default-value,keyword-arg-before-vararg,too-many-arguments
25
+ # pylint: disable-next=keyword-arg-before-vararg,too-many-arguments
26
26
  def __init__(
27
27
  self,
28
28
  fmt: str = "%(cute_levelname)s | %(cute_asctime)s | %(cute_name)s | %(cute_message)s",
@@ -1,4 +1,4 @@
1
- from typing import NamedTuple, ParamSpec, ClassVar, TypeVar, Self
1
+ from typing import NamedTuple, Final, ClassVar, Self
2
2
  from collections.abc import Callable, Iterable
3
3
  from subprocess import TimeoutExpired, Popen
4
4
  from multiprocessing import Process
@@ -18,13 +18,11 @@ __all__ = ("Caffeinate", "osascript")
18
18
  CAFFEINATE = Path("/usr/bin/caffeinate") # This is a hard-coded location on macOS
19
19
  KILL_WAIT_SECONDS: int = 60 # How long to .wait after .send_signal
20
20
 
21
- P = ParamSpec("P")
22
- R = TypeVar("R")
23
-
24
21
 
25
22
  class Caffeinate:
26
23
  """A small wrapper class around macOS' CLI tool Caffeinate"""
27
24
 
25
+ SUPPORTED: Final[ClassVar[bool]] = CAFFEINATE.exists()
28
26
  _finalizing: ClassVar[bool] = False
29
27
  _instances_lock: ClassVar[Lock] = Lock()
30
28
  _instances: ClassVar[set[Caffeinate]] = set() # Self makes mypy upset here; maybe b/c of subclassing? :/
@@ -43,7 +41,7 @@ class Caffeinate:
43
41
  msg = "The context manager is meant for managing the subprocess' lifetime, which is disable by .signal == 0, consider using .start() / .stop() instead."
44
42
  super().__init__(msg)
45
43
 
46
- # pylint: disable=too-many-arguments
44
+ # pylint: disable-next=too-many-arguments
47
45
  def __init__(
48
46
  self,
49
47
  # Passed through to CLI tool
@@ -56,7 +54,7 @@ class Caffeinate:
56
54
  user: bool = False,
57
55
  timeout: int | None = None,
58
56
  wait: int | Popen | Process | None = None,
59
- # For Caeffinate class itself
57
+ # For Caffeinate class itself
60
58
  signal: Signals | int = Signals.SIGTERM,
61
59
  block: bool = False,
62
60
  ) -> None:
@@ -75,13 +73,13 @@ class Caffeinate:
75
73
  disk: If True: Create an assertion to prevent the disk from idle sleeping.
76
74
  system: If True: Create an assertion to prevent the system from sleeping. This assertion is valid only when system is running on AC power.
77
75
  user: If True: Create an assertion to declare that user is active. If the display is off, this option turns the display on and prevents the display from going into idle sleep. If a timeout is not specified with '-t' option, then this assertion is taken with a default of 5 second timeout.
78
- timeout: Specifies the timeout value in seconds for which this assertion has to be valid. The assertion is dropped after the specified timeout. Timeout value is not used by the Caeffinate CLI when cmd is passed. Note: this timeout is passed to the Caffeinate CLI command, it is not enforced by python
79
- wait: Waits for the process with the specified pid to exit. Once the the process exits, the assertion is also released. This option is ignored by the Caeffinate CLI when cmd is passed.
76
+ timeout: Specifies the timeout value in seconds for which this assertion has to be valid. The assertion is dropped after the specified timeout. Timeout value is not used by the Caffeinate CLI when cmd is passed. Note: this timeout is passed to the Caffeinate CLI command, it is not enforced by python
77
+ wait: Waits for the process with the specified pid to exit. Once the the process exits, the assertion is also released. This option is ignored by the Caffeinate CLI when cmd is passed.
80
78
  This option conflicts with cmd.
81
79
  signal: The signal used to kill the child process (if cmd likely the process Caffeinate execs into). If 0, do not kill it
82
80
  block: If True: Block until cmd has finished executing before returning from __enter__
83
81
  """
84
- if not CAFFEINATE.exists():
82
+ if not self.SUPPORTED:
85
83
  raise NotImplementedError(f"This class is only available on macOS via: {CAFFEINATE}")
86
84
  if (
87
85
  isinstance(timeout, float)
@@ -128,7 +126,7 @@ class Caffeinate:
128
126
  pid = getpid()
129
127
  with self._instances_lock:
130
128
  if self._finalizing:
131
- raise PythonFinalizationError("No more new Caeffinate subprocesses are allowed")
129
+ raise PythonFinalizationError("No more new Caffeinate subprocesses are allowed")
132
130
  self._data = self._Data(pid, Popen(self._cmd)) # pylint: disable=consider-using-with
133
131
  self._instances.add(self)
134
132
  self._log.debug("Created Popen(%s), pid=%s", self._cmd, self._data.proc.pid)
@@ -157,7 +155,7 @@ class Caffeinate:
157
155
  self._stop(signal)
158
156
 
159
157
  @classmethod
160
- def decorate(
158
+ def decorate[**P, R](
161
159
  cls, cmd: list[Path | str | None] | None = None, **init_kwargs: object
162
160
  ) -> Callable[[Callable[P, R]], Callable[P, R]]:
163
161
  """A decorator to wrap a function with a Caffeinate instance
@@ -249,4 +247,5 @@ class Caffeinate:
249
247
 
250
248
 
251
249
  assert 0 not in Signals, "0 not expected in signal.Signals as it's a nop"
252
- atexit.register(Caffeinate._atexit) # pylint: disable=protected-access
250
+ if Caffeinate.SUPPORTED:
251
+ atexit.register(Caffeinate._atexit) # pylint: disable=protected-access
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zstdlib
3
- Version: 0.10.3
3
+ Version: 0.10.5
4
4
  Summary: A set of useful python utilities
5
5
  License: GPLv3
6
6
  Project-URL: Homepage, https://github.com/zwimer/zstdlib
@@ -6,6 +6,7 @@ tests/test_ansi.py
6
6
  tests/test_enum.py
7
7
  tests/test_exc_capture.py
8
8
  tests/test_frozen.py
9
+ tests/test_hybridmethod.py
9
10
  tests/test_io.py
10
11
  tests/test_lazy.py
11
12
  tests/test_not_set.py
@@ -19,6 +20,7 @@ zstdlib/ansi.py
19
20
  zstdlib/enum.py
20
21
  zstdlib/exc_capture.py
21
22
  zstdlib/frozen.py
23
+ zstdlib/hybridmethod.py
22
24
  zstdlib/io.py
23
25
  zstdlib/lazy.py
24
26
  zstdlib/macos.py
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