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/iterators.py CHANGED
@@ -22,66 +22,61 @@ class PeekIterator(ta.Iterator[T]):
22
22
 
23
23
  _item: T
24
24
 
25
- def __iter__(self) -> ta.Iterator[T]:
25
+ def __iter__(self) -> ta.Self:
26
26
  return self
27
27
 
28
28
  @property
29
29
  def done(self) -> bool:
30
30
  try:
31
31
  self.peek()
32
- return False
33
32
  except StopIteration:
34
33
  return True
34
+ else:
35
+ return False
35
36
 
36
37
  def __next__(self) -> T:
37
38
  if self._next_item is not _MISSING:
38
39
  self._item = ta.cast(T, self._next_item)
39
40
  self._next_item = _MISSING
40
41
  else:
41
- try:
42
- self._item = next(self._it)
43
- except StopIteration:
44
- raise
42
+ self._item = next(self._it)
45
43
  self._pos += 1
46
44
  return self._item
47
45
 
48
46
  def peek(self) -> T:
49
47
  if self._next_item is not _MISSING:
50
48
  return ta.cast(T, self._next_item)
51
- try:
52
- self._next_item = next(self._it)
53
- except StopIteration:
54
- raise
49
+ self._next_item = next(self._it)
55
50
  return self._next_item
56
51
 
57
52
  def next_peek(self) -> T:
58
53
  next(self)
59
54
  return self.peek()
60
55
 
61
- def takewhile(self, fn):
56
+ def takewhile(self, fn: ta.Callable[[T], bool]) -> ta.Iterator[T]:
62
57
  while fn(self.peek()):
63
58
  yield next(self)
64
59
 
65
- def skipwhile(self, fn):
60
+ def skipwhile(self, fn: ta.Callable[[T], bool]) -> None:
66
61
  while fn(self.peek()):
67
62
  next(self)
68
63
 
69
- def takeuntil(self, fn):
64
+ def takeuntil(self, fn: ta.Callable[[T], bool]) -> ta.Iterator[T]:
70
65
  return self.takewhile(lambda e: not fn(e))
71
66
 
72
- def skipuntil(self, fn):
67
+ def skipuntil(self, fn: ta.Callable[[T], bool]) -> None:
73
68
  self.skipwhile(lambda e: not fn(e))
74
69
 
75
- def takethrough(self, pos):
70
+ def takethrough(self, pos: int) -> ta.Iterator[T]:
76
71
  return self.takewhile(lambda _: self._pos < pos)
77
72
 
78
- def skipthrough(self, pos):
73
+ def skipthrough(self, pos: int) -> None:
79
74
  self.skipwhile(lambda _: self._pos < pos)
80
75
 
81
- def taketo(self, pos):
76
+ def taketo(self, pos: int) -> ta.Iterator[T]:
82
77
  return self.takethrough(pos - 1)
83
78
 
84
- def skipto(self, pos):
79
+ def skipto(self, pos: int) -> None:
85
80
  self.skipthrough(pos - 1)
86
81
 
87
82
 
@@ -90,7 +85,7 @@ class ProxyIterator(ta.Iterator[T]):
90
85
  def __init__(self, fn: ta.Callable[[], T]) -> None:
91
86
  self._fn = fn
92
87
 
93
- def __iter__(self) -> ta.Iterator[T]:
88
+ def __iter__(self) -> ta.Self:
94
89
  return self
95
90
 
96
91
  def __next__(self) -> T:
@@ -103,9 +98,9 @@ class PrefetchIterator(ta.Iterator[T]):
103
98
  super().__init__()
104
99
 
105
100
  self._fn = fn
106
- self._deque: ta.Deque[T] = collections.deque()
101
+ self._deque: collections.deque[T] = collections.deque()
107
102
 
108
- def __iter__(self) -> ta.Iterator[T]:
103
+ def __iter__(self) -> ta.Self:
109
104
  return self
110
105
 
111
106
  def push(self, item) -> None:
@@ -116,7 +111,7 @@ class PrefetchIterator(ta.Iterator[T]):
116
111
  return self._deque.popleft()
117
112
  except IndexError:
118
113
  if self._fn is None:
119
- raise StopIteration
114
+ raise StopIteration from None
120
115
  return self._fn()
121
116
 
122
117
 
@@ -126,9 +121,9 @@ class RetainIterator(ta.Iterator[T]):
126
121
  super().__init__()
127
122
 
128
123
  self._fn = fn
129
- self._deque: ta.Deque[T] = collections.deque()
124
+ self._deque: collections.deque[T] = collections.deque()
130
125
 
131
- def __iter__(self) -> ta.Iterator[T]:
126
+ def __iter__(self) -> ta.Self:
132
127
  return self
133
128
 
134
129
  def pop(self) -> None:
omlish/json.py CHANGED
@@ -1,5 +1,6 @@
1
1
  import functools
2
2
  import json as _json
3
+ import typing as ta
3
4
 
4
5
 
5
6
  dump = _json.dump
@@ -15,25 +16,25 @@ loads = _json.loads
15
16
 
16
17
  PRETTY_INDENT = 2
17
18
 
18
- PRETTY_KWARGS = dict(
19
+ PRETTY_KWARGS: ta.Mapping[str, ta.Any] = dict(
19
20
  indent=PRETTY_INDENT,
20
21
  )
21
22
 
22
- dump_pretty = functools.partial(dump, **PRETTY_KWARGS)
23
- dumps_pretty = functools.partial(dumps, **PRETTY_KWARGS)
23
+ dump_pretty: ta.Callable[..., bytes] = functools.partial(dump, **PRETTY_KWARGS) # type: ignore
24
+ dumps_pretty: ta.Callable[..., str] = functools.partial(dumps, **PRETTY_KWARGS)
24
25
 
25
26
  ##
26
27
 
27
28
 
28
29
  COMPACT_SEPARATORS = (',', ':')
29
30
 
30
- COMPACT_KWARGS = dict(
31
+ COMPACT_KWARGS: ta.Mapping[str, ta.Any] = dict(
31
32
  indent=0,
32
33
  separators=COMPACT_SEPARATORS,
33
34
  )
34
35
 
35
- dump_compact = functools.partial(dump, **COMPACT_KWARGS)
36
- dumps_compact = functools.partial(dumps, **COMPACT_KWARGS)
36
+ dump_compact: ta.Callable[..., bytes] = functools.partial(dump, **COMPACT_KWARGS) # type: ignore
37
+ dumps_compact: ta.Callable[..., str] = functools.partial(dumps, **COMPACT_KWARGS)
37
38
 
38
39
 
39
40
  ##
omlish/lang/__init__.py CHANGED
@@ -8,7 +8,7 @@ from .classes import ( # noqa
8
8
  Callable,
9
9
  Descriptor,
10
10
  Final,
11
- FinalException,
11
+ FinalError,
12
12
  LazySingleton,
13
13
  Marker,
14
14
  Namespace,
@@ -18,7 +18,7 @@ from .classes import ( # noqa
18
18
  PackageSealed,
19
19
  Picklable,
20
20
  Sealed,
21
- SealedException,
21
+ SealedError,
22
22
  SimpleMetaDict,
23
23
  Singleton,
24
24
  Virtual,
@@ -74,10 +74,12 @@ from .datetimes import ( # noqa
74
74
  )
75
75
 
76
76
  from .descriptors import ( # noqa
77
- AccessForbiddenException,
77
+ AccessForbiddenError,
78
78
  access_forbidden,
79
+ attr_property,
79
80
  classonly,
80
81
  is_method_descriptor,
82
+ item_property,
81
83
  unwrap_method_descriptors,
82
84
  )
83
85
 
@@ -87,8 +89,9 @@ from .exceptions import ( # noqa
87
89
 
88
90
  from .functions import ( # noqa
89
91
  Args,
90
- VoidException,
92
+ VoidError,
91
93
  constant,
94
+ finally_,
92
95
  identity,
93
96
  is_lambda,
94
97
  is_none,
@@ -96,6 +99,7 @@ from .functions import ( # noqa
96
99
  maybe_call,
97
100
  periodically,
98
101
  raise_,
102
+ raising,
99
103
  recurse,
100
104
  try_,
101
105
  unwrap_func,
@@ -136,6 +140,7 @@ from .objects import ( # noqa
136
140
  arg_repr,
137
141
  attr_repr,
138
142
  new_type,
143
+ opt_repr,
139
144
  super_meta,
140
145
  )
141
146
 
omlish/lang/cached.py CHANGED
@@ -207,7 +207,7 @@ class _CachedFunctionDescriptor(_CachedFunction[T]):
207
207
  return bound
208
208
 
209
209
 
210
- def cached_function(fn=None, **kwargs):
210
+ def cached_function(fn=None, **kwargs): # noqa
211
211
  if fn is None:
212
212
  return functools.partial(cached_function, **kwargs)
213
213
  opts = _CachedFunction.Opts(**kwargs)
@@ -217,9 +217,6 @@ def cached_function(fn=None, **kwargs):
217
217
  return _CachedFunctionDescriptor(fn, scope, opts=opts)
218
218
 
219
219
 
220
- cached_function = cached_function
221
-
222
-
223
220
  ##
224
221
 
225
222
 
@@ -269,7 +266,7 @@ class _CachedProperty:
269
266
  raise TypeError(self._name)
270
267
 
271
268
 
272
- def cached_property(fn=None, **kwargs):
269
+ def cached_property(fn=None, **kwargs): # noqa
273
270
  if fn is None:
274
271
  return functools.partial(cached_property, **kwargs)
275
272
  return _CachedProperty(fn, **kwargs)
@@ -8,13 +8,13 @@ from .abstract import ( # noqa
8
8
 
9
9
  from .restrict import ( # noqa
10
10
  Final,
11
- FinalException,
11
+ FinalError,
12
12
  NoBool,
13
13
  NotInstantiable,
14
14
  NotPicklable,
15
15
  PackageSealed,
16
16
  Sealed,
17
- SealedException,
17
+ SealedError,
18
18
  no_bool,
19
19
  )
20
20
 
@@ -23,7 +23,7 @@ def make_abstract(obj: T) -> T:
23
23
  return obj
24
24
 
25
25
 
26
- class Abstract(abc.ABC):
26
+ class Abstract(abc.ABC): # noqa
27
27
  __slots__ = ()
28
28
 
29
29
  def __forceabstract__(self):
@@ -31,7 +31,7 @@ class Abstract(abc.ABC):
31
31
 
32
32
  setattr(__forceabstract__, '__isabstractmethod__', True)
33
33
 
34
- def __init_subclass__(cls, **kwargs) -> None:
34
+ def __init_subclass__(cls, **kwargs: ta.Any) -> None:
35
35
  if Abstract in cls.__bases__:
36
36
  cls.__forceabstract__ = Abstract.__forceabstract__ # type: ignore
37
37
  else:
@@ -8,9 +8,9 @@ from .abstract import is_abstract
8
8
  ##
9
9
 
10
10
 
11
- class FinalException(TypeError):
11
+ class FinalError(TypeError):
12
12
 
13
- def __init__(self, _type: ta.Type) -> None:
13
+ def __init__(self, _type: type) -> None:
14
14
  super().__init__()
15
15
 
16
16
  self._type = _type
@@ -22,17 +22,17 @@ class FinalException(TypeError):
22
22
  class Final(Abstract):
23
23
  __slots__ = ()
24
24
 
25
- def __init_subclass__(cls, **kwargs) -> None:
25
+ def __init_subclass__(cls, **kwargs: ta.Any) -> None:
26
26
  super().__init_subclass__(**kwargs)
27
27
 
28
28
  abstracts: set[ta.Any] = set()
29
29
  for base in cls.__bases__:
30
30
  if base is Abstract:
31
- raise FinalException(base)
31
+ raise FinalError(base)
32
32
  elif base is Final:
33
33
  continue
34
34
  elif Final in base.__mro__:
35
- raise FinalException(base)
35
+ raise FinalError(base)
36
36
  else:
37
37
  abstracts.update(getattr(base, '__abstractmethods__', []))
38
38
 
@@ -40,15 +40,15 @@ class Final(Abstract):
40
40
  try:
41
41
  v = cls.__dict__[a]
42
42
  except KeyError:
43
- raise FinalException(a)
43
+ raise FinalError(a) from None
44
44
  if is_abstract(v):
45
- raise FinalException(a)
45
+ raise FinalError(a)
46
46
 
47
47
 
48
48
  ##
49
49
 
50
50
 
51
- class SealedException(TypeError):
51
+ class SealedError(TypeError):
52
52
 
53
53
  def __init__(self, _type) -> None:
54
54
  super().__init__()
@@ -62,24 +62,24 @@ class SealedException(TypeError):
62
62
  class Sealed:
63
63
  __slots__ = ()
64
64
 
65
- def __init_subclass__(cls, **kwargs) -> None:
65
+ def __init_subclass__(cls, **kwargs: ta.Any) -> None:
66
66
  for base in cls.__bases__:
67
67
  if base is not Abstract:
68
68
  if Sealed in base.__bases__:
69
69
  if cls.__module__ != base.__module__:
70
- raise SealedException(base)
70
+ raise SealedError(base)
71
71
  super().__init_subclass__(**kwargs)
72
72
 
73
73
 
74
74
  class PackageSealed:
75
75
  __slots__ = ()
76
76
 
77
- def __init_subclass__(cls, **kwargs) -> None:
77
+ def __init_subclass__(cls, **kwargs: ta.Any) -> None:
78
78
  for base in cls.__bases__:
79
79
  if base is not Abstract:
80
80
  if PackageSealed in base.__bases__:
81
81
  if cls.__module__.split('.')[:-1] != base.__module__.split('.')[:-1]:
82
- raise SealedException(base)
82
+ raise SealedError(base)
83
83
  super().__init_subclass__(**kwargs)
84
84
 
85
85
 
@@ -89,7 +89,7 @@ class PackageSealed:
89
89
  class NotInstantiable(Abstract):
90
90
  __slots__ = ()
91
91
 
92
- def __new__(cls, *args, **kwargs) -> ta.NoReturn:
92
+ def __new__(cls, *args: ta.Any, **kwargs: ta.Any) -> ta.NoReturn: # noqa
93
93
  raise TypeError
94
94
 
95
95
 
@@ -133,5 +133,5 @@ class _NoBoolDescriptor:
133
133
  return self._fn(*args, **kwargs)
134
134
 
135
135
 
136
- def no_bool(fn):
136
+ def no_bool(fn): # noqa
137
137
  return _NoBoolDescriptor(fn)
@@ -100,7 +100,7 @@ class Singleton:
100
100
  def __new__(cls):
101
101
  return cls.__dict__[_SINGLETON_INSTANCE_ATTR]
102
102
 
103
- def __init_subclass__(cls, **kwargs):
103
+ def __init_subclass__(cls, **kwargs: ta.Any) -> None:
104
104
  super().__init_subclass__(**kwargs)
105
105
  _set_singleton_instance(super().__new__(cls)) # noqa
106
106
 
@@ -15,10 +15,10 @@ Ty = ta.TypeVar('Ty', bound=type)
15
15
 
16
16
 
17
17
  def _make_not_instantiable():
18
- def __new__(cls, *args, **kwargs):
18
+ def __new__(cls, *args, **kwargs): # noqa
19
19
  raise TypeError(cls)
20
20
 
21
- def __init__(self, *args, **kwargs):
21
+ def __init__(self, *args, **kwargs): # noqa
22
22
  raise TypeError(self)
23
23
 
24
24
  return {
@@ -49,7 +49,7 @@ class _VirtualMeta(abc.ABCMeta):
49
49
  reqset -= set(mro_cls.__dict__)
50
50
  return reqset
51
51
 
52
- def __subclasshook__(cls, subclass):
52
+ def __subclasshook__(cls, subclass): # noqa
53
53
  if cls is not kls:
54
54
  return super(kls, cls).__subclasshook__(subclass) # type: ignore
55
55
  if get_missing_reqs(subclass):
@@ -117,11 +117,11 @@ class Callable(NotInstantiable, Final, ta.Generic[T]):
117
117
  raise TypeError
118
118
 
119
119
  @classmethod
120
- def __instancecheck__(cls, instance):
120
+ def __instancecheck__(cls, instance: object) -> bool:
121
121
  return callable(instance)
122
122
 
123
123
  @classmethod
124
- def __subclasscheck__(cls, subclass):
124
+ def __subclasscheck__(cls, subclass: type) -> bool:
125
125
  if not hasattr(subclass, '__call__'):
126
126
  return False
127
127
  call = subclass.__call__
omlish/lang/clsdct.py CHANGED
@@ -60,7 +60,7 @@ class ClassDctFn:
60
60
  return self._fn(cls_dct, *args, **kwargs)
61
61
 
62
62
 
63
- def cls_dct_fn(offset=1, *, wrap=True):
63
+ def cls_dct_fn(offset=1, *, wrap=True): # noqa
64
64
  def outer(fn):
65
65
  return ClassDctFn(fn, offset, wrap=wrap)
66
66
 
omlish/lang/cmp.py CHANGED
@@ -18,7 +18,7 @@ class InfinityType:
18
18
  def __le__(self, other: ta.Any) -> bool:
19
19
  return False
20
20
 
21
- def __eq__(self, other: ta.Any) -> bool:
21
+ def __eq__(self, other: object) -> bool:
22
22
  return isinstance(other, self.__class__)
23
23
 
24
24
  def __gt__(self, other: ta.Any) -> bool:
@@ -47,7 +47,7 @@ class NegativeInfinityType:
47
47
  def __le__(self, other: ta.Any) -> bool:
48
48
  return True
49
49
 
50
- def __eq__(self, other: ta.Any) -> bool:
50
+ def __eq__(self, other: object) -> bool:
51
51
  return isinstance(other, self.__class__)
52
52
 
53
53
  def __gt__(self, other: ta.Any) -> bool:
@@ -19,8 +19,8 @@ class ContextManaged:
19
19
 
20
20
  def __exit__(
21
21
  self,
22
- exc_type: ta.Type[Exception] | None,
23
- exc_val: Exception | None,
22
+ exc_type: type[BaseException] | None,
23
+ exc_val: BaseException | None,
24
24
  exc_tb: types.TracebackType | None,
25
25
  ) -> bool | None:
26
26
  return None
@@ -28,7 +28,7 @@ class ContextManaged:
28
28
 
29
29
  class NopContextManaged(ContextManaged):
30
30
 
31
- def __init_subclass__(cls, **kwargs):
31
+ def __init_subclass__(cls, **kwargs: ta.Any) -> None:
32
32
  raise TypeError
33
33
 
34
34
 
@@ -37,7 +37,7 @@ NOP_CONTEXT_MANAGED = NopContextManaged()
37
37
 
38
38
  class NopContextManager:
39
39
 
40
- def __init_subclass__(cls, **kwargs):
40
+ def __init_subclass__(cls, **kwargs: ta.Any) -> None:
41
41
  raise TypeError
42
42
 
43
43
  def __call__(self, *args, **kwargs):
@@ -84,11 +84,11 @@ def disposing(obj: T, attr: str = 'dispose') -> ta.Iterator[T]:
84
84
 
85
85
 
86
86
  @contextlib.contextmanager
87
- def breakpoint_on_exception():
87
+ def breakpoint_on_exception(): # noqa
88
88
  try:
89
89
  yield
90
90
  except Exception as e: # noqa
91
- breakpoint()
91
+ breakpoint() # noqa
92
92
  raise
93
93
 
94
94
 
@@ -102,7 +102,7 @@ def context_var_setting(var: contextvars.ContextVar[T], val: T) -> ta.Iterator[T
102
102
 
103
103
 
104
104
  @contextlib.contextmanager
105
- def attr_setting(obj, attr, val, *, default=None):
105
+ def attr_setting(obj, attr, val, *, default=None): # noqa
106
106
  not_set = object()
107
107
  orig = getattr(obj, attr, not_set)
108
108
  try:
@@ -146,8 +146,8 @@ class ExitStacked:
146
146
 
147
147
  def __exit__(
148
148
  self,
149
- exc_type: ta.Type[Exception] | None,
150
- exc_val: Exception | None,
149
+ exc_type: type[BaseException] | None,
150
+ exc_val: BaseException | None,
151
151
  exc_tb: types.TracebackType | None,
152
152
  ) -> bool | None:
153
153
  self._exit_stack.__exit__(exc_type, exc_val, exc_tb)
@@ -212,10 +212,8 @@ class ContextWrapped:
212
212
  raise TypeError(cm)
213
213
  ret = type(self)(fn, cm)
214
214
  if self._name is not None:
215
- try:
215
+ with contextlib.suppress(TypeError):
216
216
  instance.__dict__[self._name] = ret
217
- except TypeError:
218
- pass
219
217
  return ret
220
218
 
221
219
  def __call__(self, *args, **kwargs):
@@ -228,7 +226,7 @@ class ContextWrapped:
228
226
  return self._fn[0](*args, **kwargs)
229
227
 
230
228
 
231
- def context_wrapped(cm): # ContextWrappable -> ta.Callable[[CallableT], CallableT]:
229
+ def context_wrapped(cm): # ContextWrappable -> ta.Callable[[CallableT], CallableT]: # noqa
232
230
  def inner(fn):
233
231
  return ContextWrapped(fn, cm)
234
232
  return inner
@@ -238,7 +236,7 @@ def context_wrapped(cm): # ContextWrappable -> ta.Callable[[CallableT], Callabl
238
236
 
239
237
 
240
238
  Lockable = ta.Callable[[], ta.ContextManager]
241
- DefaultLockable = ta.Union[None, bool, Lockable, ta.ContextManager]
239
+ DefaultLockable = bool | Lockable | ta.ContextManager | None
242
240
 
243
241
 
244
242
  def default_lock(value: DefaultLockable, default: DefaultLockable) -> Lockable:
@@ -1,4 +1,5 @@
1
1
  import functools
2
+ import operator
2
3
  import typing as ta
3
4
 
4
5
 
@@ -8,6 +9,17 @@ T = ta.TypeVar('T')
8
9
  ##
9
10
 
10
11
 
12
+ def attr_property(n: str):
13
+ return property(operator.attrgetter(n))
14
+
15
+
16
+ def item_property(n: str):
17
+ return property(operator.itemgetter(n))
18
+
19
+
20
+ ##
21
+
22
+
11
23
  BUILTIN_METHOD_DESCRIPTORS = (classmethod, staticmethod)
12
24
 
13
25
 
@@ -28,7 +40,7 @@ def unwrap_method_descriptors(fn: ta.Callable) -> ta.Callable:
28
40
  ##
29
41
 
30
42
 
31
- class AccessForbiddenException(Exception):
43
+ class AccessForbiddenError(Exception):
32
44
 
33
45
  def __init__(self, name: str | None = None, *args: ta.Any, **kwargs: ta.Any) -> None:
34
46
  super().__init__(*((name,) if name is not None else ()), *args, **kwargs) # noqa
@@ -42,17 +54,17 @@ class AccessForbiddenDescriptor:
42
54
 
43
55
  self._name = name
44
56
 
45
- def __set_name__(self, owner: ta.Type, name: str) -> None:
57
+ def __set_name__(self, owner: type, name: str) -> None:
46
58
  if self._name is None:
47
59
  self._name = name
48
60
  elif name != self._name:
49
61
  raise NameError(name)
50
62
 
51
63
  def __get__(self, instance, owner=None):
52
- raise AccessForbiddenException(self._name)
64
+ raise AccessForbiddenError(self._name)
53
65
 
54
66
 
55
- def access_forbidden():
67
+ def access_forbidden(): # noqa
56
68
  return AccessForbiddenDescriptor()
57
69
 
58
70
 
omlish/lang/exceptions.py CHANGED
@@ -1,2 +1,2 @@
1
- class Unreachable(Exception):
1
+ class Unreachable(Exception): # noqa
2
2
  pass