omlish 0.0.0.dev2__py3-none-any.whl → 0.0.0.dev3__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.

Potentially problematic release.


This version of omlish might be problematic. Click here for more details.

Files changed (118) hide show
  1. omlish/__about__.py +1 -2
  2. omlish/argparse.py +4 -4
  3. omlish/asyncs/__init__.py +2 -2
  4. omlish/asyncs/anyio.py +13 -11
  5. omlish/asyncs/asyncs.py +1 -3
  6. omlish/asyncs/futures.py +10 -9
  7. omlish/c3.py +1 -1
  8. omlish/check.py +3 -3
  9. omlish/collections/_abc.py +2 -0
  10. omlish/collections/_io_abc.py +4 -2
  11. omlish/collections/cache/__init__.py +1 -1
  12. omlish/collections/cache/descriptor.py +8 -8
  13. omlish/collections/cache/impl.py +24 -17
  14. omlish/collections/cache/types.py +1 -1
  15. omlish/collections/coerce.py +1 -1
  16. omlish/collections/frozen.py +6 -6
  17. omlish/collections/identity.py +3 -4
  18. omlish/collections/mappings.py +2 -2
  19. omlish/collections/ordered.py +7 -7
  20. omlish/collections/skiplist.py +1 -1
  21. omlish/collections/sorted.py +1 -1
  22. omlish/collections/treap.py +25 -0
  23. omlish/collections/treapmap.py +57 -5
  24. omlish/collections/unmodifiable.py +9 -9
  25. omlish/collections/utils.py +1 -1
  26. omlish/configs/flattening.py +7 -6
  27. omlish/configs/props.py +3 -3
  28. omlish/dataclasses/__init__.py +1 -1
  29. omlish/dataclasses/impl/__init__.py +17 -1
  30. omlish/dataclasses/impl/api.py +10 -11
  31. omlish/dataclasses/impl/as_.py +4 -4
  32. omlish/dataclasses/impl/exceptions.py +1 -1
  33. omlish/dataclasses/impl/fields.py +7 -7
  34. omlish/dataclasses/impl/frozen.py +2 -2
  35. omlish/dataclasses/impl/init.py +5 -5
  36. omlish/dataclasses/impl/internals.py +1 -1
  37. omlish/dataclasses/impl/metaclass.py +1 -1
  38. omlish/dataclasses/impl/order.py +1 -1
  39. omlish/dataclasses/impl/replace.py +1 -1
  40. omlish/dataclasses/impl/repr.py +4 -4
  41. omlish/dataclasses/impl/utils.py +6 -6
  42. omlish/defs.py +13 -17
  43. omlish/{procfs.py → diag/procfs.py} +22 -24
  44. omlish/diag/ps.py +47 -0
  45. omlish/{replserver → diag/replserver}/console.py +18 -20
  46. omlish/{replserver → diag/replserver}/server.py +8 -8
  47. omlish/dispatch/dispatch.py +5 -8
  48. omlish/dispatch/functions.py +1 -1
  49. omlish/dispatch/methods.py +4 -5
  50. omlish/docker.py +1 -1
  51. omlish/dynamic.py +8 -8
  52. omlish/fnpairs.py +311 -0
  53. omlish/graphs/trees.py +13 -13
  54. omlish/inject/__init__.py +7 -7
  55. omlish/inject/elements.py +1 -1
  56. omlish/inject/exceptions.py +7 -7
  57. omlish/inject/impl/elements.py +4 -4
  58. omlish/inject/impl/injector.py +5 -5
  59. omlish/inject/impl/inspect.py +2 -2
  60. omlish/inject/impl/scopes.py +9 -9
  61. omlish/inject/proxy.py +5 -5
  62. omlish/iterators.py +19 -24
  63. omlish/json.py +7 -6
  64. omlish/lang/__init__.py +9 -4
  65. omlish/lang/cached.py +2 -5
  66. omlish/lang/classes/__init__.py +2 -2
  67. omlish/lang/classes/abstract.py +2 -2
  68. omlish/lang/classes/restrict.py +14 -14
  69. omlish/lang/classes/simple.py +1 -1
  70. omlish/lang/classes/virtual.py +5 -5
  71. omlish/lang/clsdct.py +1 -1
  72. omlish/lang/cmp.py +2 -2
  73. omlish/lang/contextmanagers.py +12 -14
  74. omlish/lang/descriptors.py +16 -4
  75. omlish/lang/exceptions.py +1 -1
  76. omlish/lang/functions.py +58 -22
  77. omlish/lang/imports.py +22 -27
  78. omlish/lang/iterables.py +2 -2
  79. omlish/lang/maybes.py +1 -0
  80. omlish/lang/objects.py +15 -9
  81. omlish/lang/resolving.py +1 -1
  82. omlish/lang/strings.py +1 -1
  83. omlish/lang/typing.py +3 -3
  84. omlish/libc.py +9 -5
  85. omlish/logs/_abc.py +5 -1
  86. omlish/logs/filters.py +2 -0
  87. omlish/logs/formatters.py +6 -2
  88. omlish/logs/utils.py +1 -1
  89. omlish/marshal/base.py +3 -3
  90. omlish/marshal/exceptions.py +1 -1
  91. omlish/marshal/global_.py +10 -4
  92. omlish/marshal/objects.py +1 -2
  93. omlish/marshal/registries.py +3 -3
  94. omlish/marshal/utils.py +2 -2
  95. omlish/marshal/values.py +1 -1
  96. omlish/math.py +9 -9
  97. omlish/reflect.py +3 -3
  98. omlish/stats.py +4 -5
  99. omlish/term.py +1 -1
  100. omlish/testing/pydevd.py +26 -6
  101. omlish/testing/pytest/inject/harness.py +1 -1
  102. omlish/testing/pytest/plugins/pydevd.py +1 -1
  103. omlish/testing/pytest/plugins/switches.py +1 -1
  104. omlish/text/delimit.py +3 -6
  105. {omlish-0.0.0.dev2.dist-info → omlish-0.0.0.dev3.dist-info}/METADATA +1 -1
  106. omlish-0.0.0.dev3.dist-info/RECORD +191 -0
  107. {omlish-0.0.0.dev2.dist-info → omlish-0.0.0.dev3.dist-info}/WHEEL +1 -1
  108. omlish/lang/classes/test/test_abstract.py +0 -89
  109. omlish/lang/classes/test/test_restrict.py +0 -71
  110. omlish/lang/classes/test/test_simple.py +0 -58
  111. omlish/lang/classes/test/test_virtual.py +0 -72
  112. omlish-0.0.0.dev2.dist-info/RECORD +0 -193
  113. /omlish/{lang/classes/test → diag}/__init__.py +0 -0
  114. /omlish/{replserver → diag/replserver}/__init__.py +0 -0
  115. /omlish/{replserver → diag/replserver}/__main__.py +0 -0
  116. /omlish/sql/{_abcs.py → _abc.py} +0 -0
  117. {omlish-0.0.0.dev2.dist-info → omlish-0.0.0.dev3.dist-info}/LICENSE +0 -0
  118. {omlish-0.0.0.dev2.dist-info → omlish-0.0.0.dev3.dist-info}/top_level.txt +0 -0
omlish/lang/functions.py CHANGED
@@ -7,14 +7,21 @@ from .descriptors import is_method_descriptor
7
7
 
8
8
 
9
9
  T = ta.TypeVar('T')
10
+ P = ta.ParamSpec('P')
10
11
  CallableT = ta.TypeVar('CallableT', bound=ta.Callable)
11
12
 
12
13
 
14
+ ##
15
+
16
+
13
17
  def is_lambda(f: ta.Any) -> bool:
14
18
  l = lambda: 0
15
19
  return isinstance(f, type(l)) and f.__name__ == l.__name__
16
20
 
17
21
 
22
+ ##
23
+
24
+
18
25
  def maybe_call(obj: ta.Any, att: str, *args, default: ta.Any = None, **kwargs) -> ta.Any:
19
26
  try:
20
27
  fn = getattr(obj, att)
@@ -24,6 +31,16 @@ def maybe_call(obj: ta.Any, att: str, *args, default: ta.Any = None, **kwargs) -
24
31
  return fn(*args, **kwargs)
25
32
 
26
33
 
34
+ def recurse(fn: ta.Callable[..., T], *args, **kwargs) -> T:
35
+ def rec(*args, **kwargs) -> T:
36
+ return fn(rec, *args, **kwargs)
37
+
38
+ return rec(*args, **kwargs)
39
+
40
+
41
+ ##
42
+
43
+
27
44
  def unwrap_func(fn: ta.Callable) -> ta.Callable:
28
45
  fn, _ = unwrap_func_with_partials(fn)
29
46
  return fn
@@ -41,38 +58,51 @@ def unwrap_func_with_partials(fn: ta.Callable) -> tuple[ta.Callable, list[functo
41
58
  nxt = getattr(fn, '__wrapped__', None)
42
59
  if not callable(nxt):
43
60
  break
44
- elif nxt is fn:
61
+ if nxt is fn:
45
62
  raise TypeError(fn)
46
63
  fn = nxt
47
64
  return fn, ps
48
65
 
49
66
 
67
+ ##
68
+
69
+
50
70
  def raise_(o: BaseException) -> ta.NoReturn:
51
71
  raise o
52
72
 
53
73
 
74
+ def raising(o: BaseException) -> ta.Callable[..., ta.NoReturn]:
75
+ def inner(*args, **kwargs):
76
+ raise o
77
+ return inner
78
+
79
+
54
80
  def try_(
81
+ fn: ta.Callable[P, T],
55
82
  exc: type[Exception] | ta.Iterable[type[Exception]] = Exception,
56
83
  default: T | None = None,
57
- ) -> ta.Callable[..., T]:
58
- def outer(fn):
59
- def inner(*args, **kwargs):
60
- try:
61
- return fn(*args, **kwargs)
62
- except exct:
63
- return default
64
-
65
- return inner
84
+ ) -> ta.Callable[P, T]:
85
+ def inner(*args, **kwargs):
86
+ try:
87
+ return fn(*args, **kwargs)
88
+ except exct:
89
+ return default
66
90
 
67
91
  exct = (exc,) if isinstance(exc, type) else tuple(exc)
68
- return outer
92
+ return inner
69
93
 
70
94
 
71
- def recurse(fn: ta.Callable[..., T], *args, **kwargs) -> T:
72
- def rec(*args, **kwargs) -> T:
73
- return fn(rec, *args, **kwargs)
95
+ def finally_(fn: ta.Callable[P, T], fin: ta.Callable) -> ta.Callable[P, T]:
96
+ def inner(*args, **kwargs):
97
+ try:
98
+ return fn(*args, **kwargs)
99
+ finally:
100
+ fin()
101
+
102
+ return inner
74
103
 
75
- return rec(*args, **kwargs)
104
+
105
+ ##
76
106
 
77
107
 
78
108
  def identity(obj: T) -> T:
@@ -98,21 +128,24 @@ def is_not_none(o: ta.Any) -> bool:
98
128
  return o is not None
99
129
 
100
130
 
101
- class VoidException(Exception):
131
+ class VoidError(Exception):
102
132
  pass
103
133
 
104
134
 
105
135
  class Void:
106
136
 
107
- def __new__(cls, *args, **kwargs):
108
- raise VoidException
137
+ def __new__(cls, *args: ta.Any, **kwargs: ta.Any) -> None: # type: ignore # noqa
138
+ raise VoidError
139
+
140
+ def __init_subclass__(cls, **kwargs: ta.Any) -> None:
141
+ raise VoidError
109
142
 
110
- def __init_subclass__(cls, **kwargs):
111
- raise VoidException
112
143
 
144
+ def void(*args: ta.Any, **kwargs: ta.Any) -> ta.NoReturn:
145
+ raise VoidError
113
146
 
114
- def void(*args, **kwargs) -> ta.NoReturn:
115
- raise VoidException
147
+
148
+ ##
116
149
 
117
150
 
118
151
  _MISSING = object()
@@ -142,6 +175,9 @@ def periodically(
142
175
  return inner # type: ignore
143
176
 
144
177
 
178
+ ##
179
+
180
+
145
181
  @dc.dataclass(init=False)
146
182
  class Args:
147
183
  args: ta.Sequence[ta.Any]
omlish/lang/imports.py CHANGED
@@ -1,5 +1,6 @@
1
+ import contextlib
1
2
  import functools
2
- import importlib
3
+ import importlib.resources
3
4
  import sys
4
5
  import types
5
6
  import typing as ta
@@ -17,7 +18,7 @@ def lazy_import(name: str, package: str | None = None) -> ta.Callable[[], ta.Any
17
18
  def proxy_import(name: str, package: str | None = None) -> types.ModuleType:
18
19
  omod = None
19
20
 
20
- def __getattr__(att):
21
+ def __getattr__(att): # noqa
21
22
  nonlocal omod
22
23
  if omod is None:
23
24
  omod = importlib.import_module(name, package=package)
@@ -31,9 +32,6 @@ def proxy_import(name: str, package: str | None = None) -> types.ModuleType:
31
32
  ##
32
33
 
33
34
 
34
- _pkg_resources = lazy_import('pkg_resources')
35
-
36
-
37
35
  def import_module(dotted_path: str) -> types.ModuleType:
38
36
  if not dotted_path:
39
37
  raise ImportError(dotted_path)
@@ -42,7 +40,7 @@ def import_module(dotted_path: str) -> types.ModuleType:
42
40
  try:
43
41
  mod = getattr(mod, name)
44
42
  except AttributeError:
45
- raise AttributeError('Module %r has no attribute %r' % (mod, name))
43
+ raise AttributeError(f'Module {mod!r} has no attribute {name!r}') from None
46
44
  return mod
47
45
 
48
46
 
@@ -52,7 +50,7 @@ def import_module_attr(dotted_path: str) -> ta.Any:
52
50
  try:
53
51
  return getattr(mod, class_name)
54
52
  except AttributeError:
55
- raise AttributeError('Module %r has no attr %r' % (module_name, class_name))
53
+ raise AttributeError(f'Module {module_name!r} has no attr {class_name!r}') from None
56
54
 
57
55
 
58
56
  SPECIAL_IMPORTABLE: ta.AbstractSet[str] = frozenset([
@@ -65,46 +63,43 @@ def yield_importable(
65
63
  package_root: str,
66
64
  *,
67
65
  recursive: bool = False,
68
- filter: ta.Callable[[str], bool] | None = None,
66
+ filter: ta.Callable[[str], bool] | None = None, # noqa
69
67
  include_special: bool = False,
70
68
  ) -> ta.Iterator[str]:
71
- def rec(dir):
72
- if dir.split('.')[-1] == '__pycache__':
69
+ def rec(cur):
70
+ if cur.split('.')[-1] == '__pycache__':
73
71
  return
74
72
 
75
73
  try:
76
- module = sys.modules[dir]
74
+ module = sys.modules[cur]
77
75
  except KeyError:
78
76
  try:
79
- __import__(dir)
77
+ __import__(cur)
80
78
  except ImportError:
81
79
  return
82
- module = sys.modules[dir]
80
+ module = sys.modules[cur]
83
81
 
84
82
  # FIXME: pyox
85
83
  if getattr(module, '__file__', None) is None:
86
84
  return
87
85
 
88
- for file in _pkg_resources().resource_listdir(dir, '.'):
89
- if file.endswith('.py'):
90
- if not (include_special or file not in SPECIAL_IMPORTABLE):
86
+ for file in importlib.resources.files(cur).iterdir():
87
+ if file.is_file() and file.name.endswith('.py'):
88
+ if not (include_special or file.name not in SPECIAL_IMPORTABLE):
91
89
  continue
92
90
 
93
- name = dir + '.' + file[:-3]
91
+ name = cur + '.' + file.name[:-3]
94
92
  if filter is not None and not filter(name):
95
93
  continue
96
94
 
97
95
  yield name
98
96
 
99
- elif recursive and '.' not in file:
100
- name = dir + '.' + file
97
+ elif recursive and file.is_dir():
98
+ name = cur + '.' + file.name
101
99
  if filter is not None and not filter(name):
102
100
  continue
103
-
104
- try:
101
+ with contextlib.suppress(ImportError, NotImplementedError):
105
102
  yield from rec(name)
106
- except (ImportError, NotImplementedError):
107
- pass
108
103
 
109
104
  yield from rec(package_root)
110
105
 
@@ -112,10 +107,10 @@ def yield_importable(
112
107
  def yield_import_all(
113
108
  package_root: str,
114
109
  *,
115
- globals: dict[str, ta.Any] | None = None,
116
- locals: dict[str, ta.Any] | None = None,
110
+ globals: dict[str, ta.Any] | None = None, # noqa
111
+ locals: dict[str, ta.Any] | None = None, # noqa
117
112
  recursive: bool = False,
118
- filter: ta.Callable[[str], bool] | None = None,
113
+ filter: ta.Callable[[str], bool] | None = None, # noqa
119
114
  include_special: bool = False,
120
115
  ) -> ta.Iterator[str]:
121
116
  for import_path in yield_importable(
@@ -132,7 +127,7 @@ def import_all(
132
127
  package_root: str,
133
128
  *,
134
129
  recursive: bool = False,
135
- filter: ta.Callable[[str], bool] | None = None,
130
+ filter: ta.Callable[[str], bool] | None = None, # noqa
136
131
  include_special: bool = False,
137
132
  ) -> None:
138
133
  for _ in yield_import_all(
omlish/lang/iterables.py CHANGED
@@ -28,13 +28,13 @@ def exhaust(it: ta.Iterable[ta.Any]) -> None:
28
28
  pass
29
29
 
30
30
 
31
- def peek(vs: ta.Iterable[T]) -> ta.Tuple[T, ta.Iterator[T]]:
31
+ def peek(vs: ta.Iterable[T]) -> tuple[T, ta.Iterator[T]]:
32
32
  it = iter(vs)
33
33
  v = next(it)
34
34
  return v, itertools.chain(iter((v,)), it)
35
35
 
36
36
 
37
- Rangeable: ta.TypeAlias = int | ta.Tuple[int] | ta.Tuple[int, int] | ta.Iterable[int]
37
+ Rangeable: ta.TypeAlias = int | tuple[int] | tuple[int, int] | ta.Iterable[int]
38
38
 
39
39
 
40
40
  def asrange(i: Rangeable) -> ta.Iterable[int]:
omlish/lang/maybes.py CHANGED
@@ -63,6 +63,7 @@ class Maybe(abc.ABC, ta.Generic[T]):
63
63
 
64
64
 
65
65
  class _Maybe(Maybe[T], tuple):
66
+ __slots__ = ()
66
67
 
67
68
  @property
68
69
  def present(self) -> bool:
omlish/lang/objects.py CHANGED
@@ -9,18 +9,22 @@ T = ta.TypeVar('T')
9
9
 
10
10
 
11
11
  def attr_repr(obj: ta.Any, *attrs: str) -> str:
12
- return '%s(%s)' % (
13
- type(obj).__name__,
14
- ', '.join('%s=%r' % (attr, getattr(obj, attr)) for attr in attrs))
12
+ return f'{type(obj).__name__}({", ".join(f"{attr}={getattr(obj, attr)!r}" for attr in attrs)})'
15
13
 
16
14
 
17
15
  def arg_repr(*args, **kwargs) -> str:
18
16
  return ', '.join(*(
19
17
  list(map(repr, args)) +
20
- [f'{k}={repr(v)}' for k, v in kwargs.items()]
18
+ [f'{k}={v!r}' for k, v in kwargs.items()]
21
19
  ))
22
20
 
23
21
 
22
+ def opt_repr(obj: ta.Any) -> str | None:
23
+ if obj is None:
24
+ return None
25
+ return repr(obj)
26
+
27
+
24
28
  ##
25
29
 
26
30
 
@@ -29,7 +33,7 @@ def new_type(
29
33
  bases: ta.Sequence[ta.Any],
30
34
  namespace: ta.Mapping[str, ta.Any],
31
35
  **kwargs,
32
- ) -> ta.Type:
36
+ ) -> type:
33
37
  return types.new_class(
34
38
  name,
35
39
  tuple(bases),
@@ -40,12 +44,12 @@ def new_type(
40
44
 
41
45
  def super_meta(
42
46
  super_meta: ta.Any,
43
- meta: ta.Type,
47
+ meta: type,
44
48
  name: str,
45
49
  bases: ta.Sequence[ta.Any],
46
50
  namespace: ta.MutableMapping[str, ta.Any],
47
51
  **kwargs,
48
- ) -> ta.Type:
52
+ ) -> type:
49
53
  """Per types.new_class"""
50
54
  resolved_bases = types.resolve_bases(bases)
51
55
  if resolved_bases is not bases:
@@ -75,19 +79,21 @@ class SimpleProxy(ta.Generic[T]):
75
79
  if instance is None:
76
80
  return self
77
81
  setattr(object.__getattribute__(instance, '__wrapped__'), self._attr, value)
82
+ return None
78
83
 
79
84
  def __delete__(self, instance):
80
85
  if instance is None:
81
86
  return self
82
87
  delattr(object.__getattribute__(instance, '__wrapped__'), self._attr)
88
+ return None
83
89
 
84
- __wrapped_attrs__: ta.Iterable[str] = set()
90
+ __wrapped_attrs__: ta.ClassVar[ta.Iterable[str]] = ()
85
91
 
86
92
  def __init__(self, wrapped: T) -> None:
87
93
  super().__init__()
88
94
  object.__setattr__(self, '__wrapped__', wrapped)
89
95
 
90
- def __init_subclass__(cls, **kwargs):
96
+ def __init_subclass__(cls, **kwargs: ta.Any) -> None:
91
97
  super().__init_subclass__(**kwargs)
92
98
 
93
99
  for attr in cls.__wrapped_attrs__:
omlish/lang/resolving.py CHANGED
@@ -45,6 +45,6 @@ def get_fqcn_cls(fqcn: str, *, nocheck: bool = False) -> type:
45
45
 
46
46
 
47
47
  class Resolvable:
48
- def __init_subclass__(cls, **kwargs):
48
+ def __init_subclass__(cls, **kwargs: ta.Any) -> None:
49
49
  super().__init_subclass__(**kwargs)
50
50
  get_cls_fqcn(cls, nocheck=True)
omlish/lang/strings.py CHANGED
@@ -22,7 +22,7 @@ def camel_case(name: str) -> str:
22
22
 
23
23
  def snake_case(name: str) -> str:
24
24
  uppers: list[int | None] = [i for i, c in enumerate(name) if c.isupper()]
25
- return '_'.join([name[l:r].lower() for l, r in zip([None] + uppers, uppers + [None])]).strip('_')
25
+ return '_'.join([name[l:r].lower() for l, r in zip([None, *uppers], [*uppers, None])]).strip('_')
26
26
 
27
27
 
28
28
  def is_dunder(name: str) -> bool:
omlish/lang/typing.py CHANGED
@@ -37,13 +37,13 @@ def _update_wrapper_no_anns(wrapper, wrapped):
37
37
  return wrapper
38
38
 
39
39
 
40
- def typed_lambda(ret=_MISSING, **kw):
40
+ def typed_lambda(ret=_MISSING, **kw): # noqa
41
41
  def inner(fn):
42
42
  ns = {}
43
43
  ns['__fn'] = fn
44
44
  proto = ['def __lam(']
45
45
  call = ['return __fn(']
46
- pkw = {k: v for k, v in kw.items()}
46
+ pkw = dict(kw)
47
47
  for i, (n, t) in enumerate(pkw.items()):
48
48
  if i:
49
49
  call.append(', ')
@@ -69,7 +69,7 @@ def typed_lambda(ret=_MISSING, **kw):
69
69
  return inner
70
70
 
71
71
 
72
- def typed_partial(obj, **kw):
72
+ def typed_partial(obj, **kw): # noqa
73
73
  for k in kw:
74
74
  if k.startswith('__'):
75
75
  raise NameError(k)
omlish/libc.py CHANGED
@@ -1,3 +1,7 @@
1
+ # ruff: noqa: ANN201
2
+ # ruff: noqa: N801
3
+ # ruff: noqa: N802
4
+
1
5
  import ctypes as ct
2
6
  import errno
3
7
  import platform
@@ -37,14 +41,14 @@ def lasterr() -> tuple[int, str]:
37
41
 
38
42
 
39
43
  # int raise(int sig);
40
- libc._raise = libc['raise'] # type: ignore
41
- libc._raise.restype = ct.c_int
42
- libc._raise.argtypes = [ct.c_int]
43
- _raise = libc._raise
44
+ libc._raise = libc['raise'] # type: ignore # noqa
45
+ libc._raise.restype = ct.c_int # noqa
46
+ libc._raise.argtypes = [ct.c_int] # noqa
47
+ _raise = libc._raise # noqa
44
48
 
45
49
 
46
50
  def sigtrap() -> None:
47
- libc._raise(signal.SIGTRAP)
51
+ libc._raise(signal.SIGTRAP) # noqa
48
52
 
49
53
 
50
54
  ##
omlish/logs/_abc.py CHANGED
@@ -1,3 +1,7 @@
1
+ # ruff: noqa: A002
2
+ # ruff: noqa: N802
3
+ # ruff: noqa: N815
4
+
1
5
  import types
2
6
  import typing as ta
3
7
 
@@ -181,7 +185,7 @@ class Logger(Filterer, ta.Protocol):
181
185
 
182
186
  def log(self, level: Level, msg: str, *args: ta.Any, **kwargs: ta.Any) -> None: ...
183
187
 
184
- def findCaller(self, stack_info: bool = False, stacklevel: int = 1) -> Caller: ... #
188
+ def findCaller(self, stack_info: bool = False, stacklevel: int = 1) -> Caller: ...
185
189
 
186
190
  def makeRecord(
187
191
  self,
omlish/logs/filters.py CHANGED
@@ -1,3 +1,5 @@
1
+ # ruff: noqa: ANN201
2
+
1
3
  import logging
2
4
  import threading
3
5
 
omlish/logs/formatters.py CHANGED
@@ -1,5 +1,9 @@
1
+ # ruff: noqa: ANN201
2
+ # ruff: noqa: N802
3
+
1
4
  import datetime
2
5
  import logging
6
+ import typing as ta
3
7
 
4
8
  from .. import json
5
9
  from .. import term
@@ -20,7 +24,7 @@ class StandardLogFormatter(logging.Formatter):
20
24
 
21
25
  class ColorLogFormatter(StandardLogFormatter):
22
26
 
23
- LEVEL_COLORS = {
27
+ LEVEL_COLORS: ta.Mapping[int, term.SGRs.FG] = {
24
28
  logging.WARNING: term.SGRs.FG.BRIGHT_YELLOW,
25
29
  logging.ERROR: term.SGRs.FG.BRIGHT_RED,
26
30
  logging.CRITICAL: term.SGRs.FG.BRIGHT_RED,
@@ -39,7 +43,7 @@ class ColorLogFormatter(StandardLogFormatter):
39
43
 
40
44
  class JsonLogFormatter(logging.Formatter):
41
45
 
42
- KEYS = {
46
+ KEYS: ta.Mapping[str, bool] = {
43
47
  'name': False,
44
48
  'msg': False,
45
49
  'args': False,
omlish/logs/utils.py CHANGED
@@ -5,7 +5,7 @@ import logging
5
5
  log = logging.getLogger(__name__)
6
6
 
7
7
 
8
- def error_logging(log=log):
8
+ def error_logging(log=log): # noqa
9
9
  def outer(fn):
10
10
  @functools.wraps(fn)
11
11
  def inner(*args, **kwargs):
omlish/marshal/base.py CHANGED
@@ -81,7 +81,7 @@ from .. import check
81
81
  from .. import collections as col
82
82
  from .. import lang
83
83
  from .. import reflect as rfl
84
- from .exceptions import UnhandledTypeException
84
+ from .exceptions import UnhandledTypeError
85
85
  from .factories import Factory
86
86
  from .factories import RecursiveTypeFactory
87
87
  from .registries import Registry
@@ -152,7 +152,7 @@ class MarshalContext(BaseContext, lang.Final):
152
152
  rty = rfl.type_(o)
153
153
  if (m := check.not_none(self.factory)(self, rty)) is not None: # noqa
154
154
  return m
155
- raise UnhandledTypeException(rty)
155
+ raise UnhandledTypeError(rty)
156
156
 
157
157
 
158
158
  @dc.dataclass(frozen=True)
@@ -163,7 +163,7 @@ class UnmarshalContext(BaseContext, lang.Final):
163
163
  rty = rfl.type_(o)
164
164
  if (m := check.not_none(self.factory)(self, rty)) is not None: # noqa
165
165
  return m
166
- raise UnhandledTypeException(rty)
166
+ raise UnhandledTypeError(rty)
167
167
 
168
168
 
169
169
  ##
@@ -1,7 +1,7 @@
1
1
  from .. import reflect as rfl
2
2
 
3
3
 
4
- class UnhandledTypeException(Exception):
4
+ class UnhandledTypeError(Exception):
5
5
  @property
6
6
  def rty(self) -> rfl.Type:
7
7
  return self.args[0]
omlish/marshal/global_.py CHANGED
@@ -1,8 +1,14 @@
1
- from .registries import Registry
2
- from .standard import new_standard_marshaler_factory
1
+ import typing as ta
2
+
3
3
  from .base import MarshalContext
4
4
  from .base import UnmarshalContext
5
+ from .registries import Registry
6
+ from .standard import new_standard_marshaler_factory
5
7
  from .standard import new_standard_unmarshaler_factory
8
+ from .values import Value
9
+
10
+
11
+ T = ta.TypeVar('T')
6
12
 
7
13
 
8
14
  ##
@@ -17,7 +23,7 @@ GLOBAL_REGISTRY = Registry()
17
23
  GLOBAL_MARSHALER_FACTORY = new_standard_marshaler_factory()
18
24
 
19
25
 
20
- def marshal(obj, ty=None, **kwargs):
26
+ def marshal(obj: ta.Any, ty: type | None = None, **kwargs: ta.Any) -> Value:
21
27
  mc = MarshalContext(GLOBAL_REGISTRY, factory=GLOBAL_MARSHALER_FACTORY, **kwargs)
22
28
  return mc.make(ty if ty is not None else type(obj)).marshal(mc, obj)
23
29
 
@@ -28,6 +34,6 @@ def marshal(obj, ty=None, **kwargs):
28
34
  GLOBAL_UNMARSHALER_FACTORY = new_standard_unmarshaler_factory()
29
35
 
30
36
 
31
- def unmarshal(v, ty, **kwargs):
37
+ def unmarshal(v: Value, ty: type[T], **kwargs: ta.Any) -> T:
32
38
  uc = UnmarshalContext(GLOBAL_REGISTRY, factory=GLOBAL_UNMARSHALER_FACTORY, **kwargs)
33
39
  return uc.make(ty).unmarshal(uc, v)
omlish/marshal/objects.py CHANGED
@@ -98,8 +98,7 @@ class ObjectUnmarshaler(Unmarshaler):
98
98
  if ukf is not None:
99
99
  ukf[ks] = mv # FIXME: unmarshal?
100
100
  continue
101
- else:
102
- raise
101
+ raise
103
102
  if fi.name in kw:
104
103
  raise KeyError(f'Duplicate keys for field {fi.name!r}: {ks!r}')
105
104
  kw[fi.name] = u.unmarshal(ctx, mv)
@@ -1,13 +1,13 @@
1
- import abc
2
1
  import dataclasses as dc
3
2
  import threading
4
3
  import typing as ta
5
4
 
6
5
  from .. import check
6
+ from .. import lang
7
7
  from .. import reflect as rfl
8
8
 
9
9
 
10
- class RegistryItem(abc.ABC):
10
+ class RegistryItem(lang.Abstract):
11
11
  pass
12
12
 
13
13
 
@@ -31,7 +31,7 @@ class Registry:
31
31
  super().__init__()
32
32
  self._mtx = threading.Lock()
33
33
  self._dct: dict[rfl.Type, _TypeRegistry] = {}
34
- self._ps: ta.Sequence['Registry'] = []
34
+ self._ps: ta.Sequence[Registry] = []
35
35
 
36
36
  def register(self, rty: rfl.Type, *items: RegistryItem) -> 'Registry':
37
37
  check.isinstance(rty, rfl.TYPES)
omlish/marshal/utils.py CHANGED
@@ -19,5 +19,5 @@ class _Proxy(ta.Generic[T]):
19
19
  self.__obj = obj
20
20
 
21
21
  @classmethod
22
- def _new(cls):
23
- return (p := cls()), p._set_obj
22
+ def _new(cls) -> tuple[ta.Any, ta.Callable[[ta.Any], None]]:
23
+ return (p := cls()), p._set_obj # noqa
omlish/marshal/values.py CHANGED
@@ -13,7 +13,7 @@ Any
13
13
  import typing as ta
14
14
 
15
15
 
16
- Value = ta.Union[
16
+ Value = ta.Union[ # noqa
17
17
  None,
18
18
 
19
19
  bool,