ominfra 0.0.0.dev121__py3-none-any.whl → 0.0.0.dev123__py3-none-any.whl

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.
@@ -66,6 +66,7 @@ import subprocess
66
66
  import sys
67
67
  import textwrap
68
68
  import threading
69
+ import types
69
70
  import typing as ta
70
71
  import uuid
71
72
  import weakref # noqa
@@ -137,7 +138,7 @@ def cached_nullary(fn): # ta.Callable[..., T]) -> ta.Callable[..., T]:
137
138
  # ../../../../omlish/lite/check.py
138
139
 
139
140
 
140
- def check_isinstance(v: T, spec: ta.Union[ta.Type[T], tuple]) -> T:
141
+ def check_isinstance(v: ta.Any, spec: ta.Union[ta.Type[T], tuple]) -> T:
141
142
  if not isinstance(v, spec):
142
143
  raise TypeError(v)
143
144
  return v
@@ -255,6 +256,14 @@ def get_optional_alias_arg(spec: ta.Any) -> ta.Any:
255
256
  return it
256
257
 
257
258
 
259
+ def is_new_type(spec: ta.Any) -> bool:
260
+ if isinstance(ta.NewType, type):
261
+ return isinstance(spec, ta.NewType)
262
+ else:
263
+ # Before https://github.com/python/cpython/commit/c2f33dfc83ab270412bf243fb21f724037effa1a
264
+ return isinstance(spec, types.FunctionType) and spec.__code__ is ta.NewType.__code__.co_consts[1] # type: ignore # noqa
265
+
266
+
258
267
  def deep_subclasses(cls: ta.Type[T]) -> ta.Iterator[ta.Type[T]]:
259
268
  seen = set()
260
269
  todo = list(reversed(cls.__subclasses__()))
@@ -74,5 +74,5 @@ class JournalctlMessageBuilder:
74
74
  def feed(self, data: bytes) -> ta.Sequence[JournalctlMessage]:
75
75
  ret: ta.List[JournalctlMessage] = []
76
76
  for line in self._buf.feed(data):
77
- ret.append(self._make_message(check_isinstance(line, bytes))) # type: ignore
77
+ ret.append(self._make_message(check_isinstance(line, bytes)))
78
78
  return ret
@@ -24,6 +24,7 @@ import subprocess
24
24
  import sys
25
25
  import textwrap
26
26
  import threading
27
+ import types
27
28
  import typing as ta
28
29
  import uuid
29
30
  import weakref # noqa
@@ -220,7 +221,7 @@ def cached_nullary(fn): # ta.Callable[..., T]) -> ta.Callable[..., T]:
220
221
  # ../../../omlish/lite/check.py
221
222
 
222
223
 
223
- def check_isinstance(v: T, spec: ta.Union[ta.Type[T], tuple]) -> T:
224
+ def check_isinstance(v: ta.Any, spec: ta.Union[ta.Type[T], tuple]) -> T:
224
225
  if not isinstance(v, spec):
225
226
  raise TypeError(v)
226
227
  return v
@@ -338,6 +339,14 @@ def get_optional_alias_arg(spec: ta.Any) -> ta.Any:
338
339
  return it
339
340
 
340
341
 
342
+ def is_new_type(spec: ta.Any) -> bool:
343
+ if isinstance(ta.NewType, type):
344
+ return isinstance(spec, ta.NewType)
345
+ else:
346
+ # Before https://github.com/python/cpython/commit/c2f33dfc83ab270412bf243fb21f724037effa1a
347
+ return isinstance(spec, types.FunctionType) and spec.__code__ is ta.NewType.__code__.co_consts[1] # type: ignore # noqa
348
+
349
+
341
350
  def deep_subclasses(cls: ta.Type[T]) -> ta.Iterator[ta.Type[T]]:
342
351
  seen = set()
343
352
  todo = list(reversed(cls.__subclasses__()))
@@ -917,7 +917,7 @@ def cached_nullary(fn): # ta.Callable[..., T]) -> ta.Callable[..., T]:
917
917
  # ../../../../../omlish/lite/check.py
918
918
 
919
919
 
920
- def check_isinstance(v: T, spec: ta.Union[ta.Type[T], tuple]) -> T:
920
+ def check_isinstance(v: ta.Any, spec: ta.Union[ta.Type[T], tuple]) -> T:
921
921
  if not isinstance(v, spec):
922
922
  raise TypeError(v)
923
923
  return v
@@ -1102,6 +1102,14 @@ def get_optional_alias_arg(spec: ta.Any) -> ta.Any:
1102
1102
  return it
1103
1103
 
1104
1104
 
1105
+ def is_new_type(spec: ta.Any) -> bool:
1106
+ if isinstance(ta.NewType, type):
1107
+ return isinstance(spec, ta.NewType)
1108
+ else:
1109
+ # Before https://github.com/python/cpython/commit/c2f33dfc83ab270412bf243fb21f724037effa1a
1110
+ return isinstance(spec, types.FunctionType) and spec.__code__ is ta.NewType.__code__.co_consts[1] # type: ignore # noqa
1111
+
1112
+
1105
1113
  def deep_subclasses(cls: ta.Type[T]) -> ta.Iterator[ta.Type[T]]:
1106
1114
  seen = set()
1107
1115
  todo = list(reversed(cls.__subclasses__()))
@@ -2696,7 +2704,7 @@ class JournalctlMessageBuilder:
2696
2704
  def feed(self, data: bytes) -> ta.Sequence[JournalctlMessage]:
2697
2705
  ret: ta.List[JournalctlMessage] = []
2698
2706
  for line in self._buf.feed(data):
2699
- ret.append(self._make_message(check_isinstance(line, bytes))) # type: ignore
2707
+ ret.append(self._make_message(check_isinstance(line, bytes)))
2700
2708
  return ret
2701
2709
 
2702
2710