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.
- omlish/__about__.py +1 -2
- omlish/argparse.py +4 -4
- omlish/asyncs/__init__.py +2 -2
- omlish/asyncs/anyio.py +13 -11
- omlish/asyncs/asyncs.py +1 -3
- omlish/asyncs/futures.py +10 -9
- omlish/c3.py +1 -1
- omlish/check.py +3 -3
- omlish/collections/_abc.py +2 -0
- omlish/collections/_io_abc.py +4 -2
- omlish/collections/cache/__init__.py +1 -1
- omlish/collections/cache/descriptor.py +8 -8
- omlish/collections/cache/impl.py +24 -17
- omlish/collections/cache/types.py +1 -1
- omlish/collections/coerce.py +1 -1
- omlish/collections/frozen.py +6 -6
- omlish/collections/identity.py +3 -4
- omlish/collections/mappings.py +2 -2
- omlish/collections/ordered.py +7 -7
- omlish/collections/skiplist.py +1 -1
- omlish/collections/sorted.py +1 -1
- omlish/collections/treap.py +25 -0
- omlish/collections/treapmap.py +57 -5
- omlish/collections/unmodifiable.py +9 -9
- omlish/collections/utils.py +1 -1
- omlish/configs/flattening.py +7 -6
- omlish/configs/props.py +3 -3
- omlish/dataclasses/__init__.py +1 -1
- omlish/dataclasses/impl/__init__.py +17 -1
- omlish/dataclasses/impl/api.py +10 -11
- omlish/dataclasses/impl/as_.py +4 -4
- omlish/dataclasses/impl/exceptions.py +1 -1
- omlish/dataclasses/impl/fields.py +7 -7
- omlish/dataclasses/impl/frozen.py +2 -2
- omlish/dataclasses/impl/init.py +5 -5
- omlish/dataclasses/impl/internals.py +1 -1
- omlish/dataclasses/impl/metaclass.py +1 -1
- omlish/dataclasses/impl/order.py +1 -1
- omlish/dataclasses/impl/replace.py +1 -1
- omlish/dataclasses/impl/repr.py +4 -4
- omlish/dataclasses/impl/utils.py +6 -6
- omlish/defs.py +13 -17
- omlish/{procfs.py → diag/procfs.py} +22 -24
- omlish/diag/ps.py +47 -0
- omlish/{replserver → diag/replserver}/console.py +18 -20
- omlish/{replserver → diag/replserver}/server.py +8 -8
- omlish/dispatch/dispatch.py +5 -8
- omlish/dispatch/functions.py +1 -1
- omlish/dispatch/methods.py +4 -5
- omlish/docker.py +1 -1
- omlish/dynamic.py +8 -8
- omlish/fnpairs.py +311 -0
- omlish/graphs/trees.py +13 -13
- omlish/inject/__init__.py +7 -7
- omlish/inject/elements.py +1 -1
- omlish/inject/exceptions.py +7 -7
- omlish/inject/impl/elements.py +4 -4
- omlish/inject/impl/injector.py +5 -5
- omlish/inject/impl/inspect.py +2 -2
- omlish/inject/impl/scopes.py +9 -9
- omlish/inject/proxy.py +5 -5
- omlish/iterators.py +19 -24
- omlish/json.py +7 -6
- omlish/lang/__init__.py +9 -4
- omlish/lang/cached.py +2 -5
- omlish/lang/classes/__init__.py +2 -2
- omlish/lang/classes/abstract.py +2 -2
- omlish/lang/classes/restrict.py +14 -14
- omlish/lang/classes/simple.py +1 -1
- omlish/lang/classes/virtual.py +5 -5
- omlish/lang/clsdct.py +1 -1
- omlish/lang/cmp.py +2 -2
- omlish/lang/contextmanagers.py +12 -14
- omlish/lang/descriptors.py +16 -4
- omlish/lang/exceptions.py +1 -1
- omlish/lang/functions.py +58 -22
- omlish/lang/imports.py +22 -27
- omlish/lang/iterables.py +2 -2
- omlish/lang/maybes.py +1 -0
- omlish/lang/objects.py +15 -9
- omlish/lang/resolving.py +1 -1
- omlish/lang/strings.py +1 -1
- omlish/lang/typing.py +3 -3
- omlish/libc.py +9 -5
- omlish/logs/_abc.py +5 -1
- omlish/logs/filters.py +2 -0
- omlish/logs/formatters.py +6 -2
- omlish/logs/utils.py +1 -1
- omlish/marshal/base.py +3 -3
- omlish/marshal/exceptions.py +1 -1
- omlish/marshal/global_.py +10 -4
- omlish/marshal/objects.py +1 -2
- omlish/marshal/registries.py +3 -3
- omlish/marshal/utils.py +2 -2
- omlish/marshal/values.py +1 -1
- omlish/math.py +9 -9
- omlish/reflect.py +3 -3
- omlish/stats.py +4 -5
- omlish/term.py +1 -1
- omlish/testing/pydevd.py +26 -6
- omlish/testing/pytest/inject/harness.py +1 -1
- omlish/testing/pytest/plugins/pydevd.py +1 -1
- omlish/testing/pytest/plugins/switches.py +1 -1
- omlish/text/delimit.py +3 -6
- {omlish-0.0.0.dev2.dist-info → omlish-0.0.0.dev3.dist-info}/METADATA +1 -1
- omlish-0.0.0.dev3.dist-info/RECORD +191 -0
- {omlish-0.0.0.dev2.dist-info → omlish-0.0.0.dev3.dist-info}/WHEEL +1 -1
- omlish/lang/classes/test/test_abstract.py +0 -89
- omlish/lang/classes/test/test_restrict.py +0 -71
- omlish/lang/classes/test/test_simple.py +0 -58
- omlish/lang/classes/test/test_virtual.py +0 -72
- omlish-0.0.0.dev2.dist-info/RECORD +0 -193
- /omlish/{lang/classes/test → diag}/__init__.py +0 -0
- /omlish/{replserver → diag/replserver}/__init__.py +0 -0
- /omlish/{replserver → diag/replserver}/__main__.py +0 -0
- /omlish/sql/{_abcs.py → _abc.py} +0 -0
- {omlish-0.0.0.dev2.dist-info → omlish-0.0.0.dev3.dist-info}/LICENSE +0 -0
- {omlish-0.0.0.dev2.dist-info → omlish-0.0.0.dev3.dist-info}/top_level.txt +0 -0
omlish/collections/treapmap.py
CHANGED
|
@@ -16,6 +16,7 @@ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEM
|
|
|
16
16
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
17
17
|
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
18
18
|
"""
|
|
19
|
+
import abc
|
|
19
20
|
import random
|
|
20
21
|
import typing as ta
|
|
21
22
|
|
|
@@ -74,13 +75,38 @@ class TreapMap(PersistentMap[K, V]):
|
|
|
74
75
|
i = TreapMapIterator(
|
|
75
76
|
_st=[],
|
|
76
77
|
_n=self._n,
|
|
77
|
-
_b=False,
|
|
78
78
|
)
|
|
79
79
|
while (n := i._n) is not None and n.left is not None: # noqa
|
|
80
80
|
i._st.append(n) # noqa
|
|
81
81
|
i._n = n.left # noqa
|
|
82
82
|
return i
|
|
83
83
|
|
|
84
|
+
def iterate_from(self, k: K) -> 'TreapMapIterator[K, V]':
|
|
85
|
+
lst = treap.place(self._n, (k, None), self._c) # type: ignore
|
|
86
|
+
i = TreapMapIterator(
|
|
87
|
+
_st=lst,
|
|
88
|
+
_n=lst.pop(),
|
|
89
|
+
)
|
|
90
|
+
return i
|
|
91
|
+
|
|
92
|
+
def reverse_iterate(self) -> 'TreapMapReverseIterator[K, V]':
|
|
93
|
+
i = TreapMapReverseIterator(
|
|
94
|
+
_st=[],
|
|
95
|
+
_n=self._n,
|
|
96
|
+
)
|
|
97
|
+
while (n := i._n) is not None and n.right is not None: # noqa
|
|
98
|
+
i._st.append(n) # noqa
|
|
99
|
+
i._n = n.right # noqa
|
|
100
|
+
return i
|
|
101
|
+
|
|
102
|
+
def reverse_iterate_from(self, k: K) -> 'TreapMapReverseIterator[K, V]':
|
|
103
|
+
lst = treap.place(self._n, (k, None), self._c, desc=True) # type: ignore
|
|
104
|
+
i = TreapMapReverseIterator(
|
|
105
|
+
_st=lst,
|
|
106
|
+
_n=lst.pop(),
|
|
107
|
+
)
|
|
108
|
+
return i
|
|
109
|
+
|
|
84
110
|
def with_(self, k: K, v: V) -> 'TreapMap[K, V]':
|
|
85
111
|
node = treap.TreapNode(
|
|
86
112
|
_value=(k, v),
|
|
@@ -108,25 +134,31 @@ def new_treap_map(cmp: ta.Callable[[tuple[K, V], tuple[K, V]], int]) -> Persiste
|
|
|
108
134
|
return TreapMap(_n=None, _c=cmp)
|
|
109
135
|
|
|
110
136
|
|
|
111
|
-
class
|
|
112
|
-
__slots__ = ('_st', '_n'
|
|
137
|
+
class BaseTreapMapIterator(abc.ABC, ta.Generic[K, V]):
|
|
138
|
+
__slots__ = ('_st', '_n')
|
|
113
139
|
|
|
114
140
|
def __init__(
|
|
115
141
|
self,
|
|
116
142
|
*,
|
|
117
143
|
_st: list[treap.TreapNode[tuple[K, V]]],
|
|
118
144
|
_n: treap.TreapNode[tuple[K, V]] | None,
|
|
119
|
-
_b: bool,
|
|
120
145
|
) -> None:
|
|
121
146
|
super().__init__()
|
|
122
147
|
|
|
123
148
|
self._st = _st
|
|
124
149
|
self._n = _n
|
|
125
|
-
self._b = _b
|
|
126
150
|
|
|
127
151
|
def has_next(self) -> bool:
|
|
128
152
|
return self._n is not None
|
|
129
153
|
|
|
154
|
+
@abc.abstractmethod
|
|
155
|
+
def next(self) -> tuple[K, V]:
|
|
156
|
+
raise NotImplementedError
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class TreapMapIterator(BaseTreapMapIterator[K, V]):
|
|
160
|
+
__slots__ = BaseTreapMapIterator.__slots__
|
|
161
|
+
|
|
130
162
|
def next(self) -> tuple[K, V]:
|
|
131
163
|
n = self._n
|
|
132
164
|
if n is None:
|
|
@@ -142,3 +174,23 @@ class TreapMapIterator(ta.Generic[K, V]):
|
|
|
142
174
|
else:
|
|
143
175
|
self._n = None
|
|
144
176
|
return n.value
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
class TreapMapReverseIterator(BaseTreapMapIterator[K, V]):
|
|
180
|
+
__slots__ = BaseTreapMapIterator.__slots__
|
|
181
|
+
|
|
182
|
+
def next(self) -> tuple[K, V]:
|
|
183
|
+
n = self._n
|
|
184
|
+
if n is None:
|
|
185
|
+
raise StopIteration
|
|
186
|
+
if n.left is not None:
|
|
187
|
+
self._n = n.left
|
|
188
|
+
while self._n.right is not None:
|
|
189
|
+
self._st.append(self._n)
|
|
190
|
+
self._n = self._n.right
|
|
191
|
+
elif len(self._st) > 0:
|
|
192
|
+
self._n = self._st[-1]
|
|
193
|
+
self._st.pop()
|
|
194
|
+
else:
|
|
195
|
+
self._n = None
|
|
196
|
+
return n.value
|
|
@@ -22,12 +22,12 @@ class UnmodifiableSequence(ta.Sequence[T], Unmodifiable, lang.Final):
|
|
|
22
22
|
self._target = target
|
|
23
23
|
|
|
24
24
|
def __repr__(self) -> str:
|
|
25
|
-
return '
|
|
25
|
+
return f'{type(self).__name__}({self._target!r})'
|
|
26
26
|
|
|
27
27
|
def __contains__(self, x: ta.Any) -> bool:
|
|
28
28
|
return x in self._target
|
|
29
29
|
|
|
30
|
-
def __eq__(self, o:
|
|
30
|
+
def __eq__(self, o: object) -> bool:
|
|
31
31
|
return self._target == o
|
|
32
32
|
|
|
33
33
|
def __ge__(self, other: ta.Any) -> bool:
|
|
@@ -51,7 +51,7 @@ class UnmodifiableSequence(ta.Sequence[T], Unmodifiable, lang.Final):
|
|
|
51
51
|
def __lt__(self, other: ta.Any) -> bool:
|
|
52
52
|
return self._target < other
|
|
53
53
|
|
|
54
|
-
def __ne__(self, o:
|
|
54
|
+
def __ne__(self, o: object) -> bool:
|
|
55
55
|
return self._target != o
|
|
56
56
|
|
|
57
57
|
def __reversed__(self) -> ta.Iterator[T]:
|
|
@@ -74,7 +74,7 @@ class UnmodifiableSet(ta.AbstractSet[T], Unmodifiable, lang.Final):
|
|
|
74
74
|
self._target = target
|
|
75
75
|
|
|
76
76
|
def __repr__(self) -> str:
|
|
77
|
-
return '
|
|
77
|
+
return f'{type(self).__name__}({self._target!r})'
|
|
78
78
|
|
|
79
79
|
def __and__(self, s: ta.AbstractSet[ta.Any]) -> ta.AbstractSet[T]:
|
|
80
80
|
return self._target & s
|
|
@@ -82,7 +82,7 @@ class UnmodifiableSet(ta.AbstractSet[T], Unmodifiable, lang.Final):
|
|
|
82
82
|
def __contains__(self, x: ta.Any) -> bool:
|
|
83
83
|
return x in self._target
|
|
84
84
|
|
|
85
|
-
def __eq__(self, o:
|
|
85
|
+
def __eq__(self, o: object) -> bool:
|
|
86
86
|
return self._target == o
|
|
87
87
|
|
|
88
88
|
def __ge__(self, s: ta.AbstractSet[ta.Any]) -> bool:
|
|
@@ -103,7 +103,7 @@ class UnmodifiableSet(ta.AbstractSet[T], Unmodifiable, lang.Final):
|
|
|
103
103
|
def __lt__(self, s: ta.AbstractSet[ta.Any]) -> bool:
|
|
104
104
|
return self._target > s
|
|
105
105
|
|
|
106
|
-
def __ne__(self, o:
|
|
106
|
+
def __ne__(self, o: object) -> bool:
|
|
107
107
|
return self._target != o
|
|
108
108
|
|
|
109
109
|
def __or__(self, s: ta.AbstractSet[T]) -> ta.AbstractSet[T]: # type: ignore
|
|
@@ -130,12 +130,12 @@ class UnmodifiableMapping(ta.Mapping[K, V], Unmodifiable, lang.Final):
|
|
|
130
130
|
self._target = target
|
|
131
131
|
|
|
132
132
|
def __repr__(self) -> str:
|
|
133
|
-
return '
|
|
133
|
+
return f'{type(self).__name__}({self._target!r})'
|
|
134
134
|
|
|
135
135
|
def __contains__(self, o: ta.Any) -> bool:
|
|
136
136
|
return o in self._target
|
|
137
137
|
|
|
138
|
-
def __eq__(self, o:
|
|
138
|
+
def __eq__(self, o: object) -> bool:
|
|
139
139
|
return self._target == o
|
|
140
140
|
|
|
141
141
|
def __ge__(self, other: ta.Any) -> bool:
|
|
@@ -159,7 +159,7 @@ class UnmodifiableMapping(ta.Mapping[K, V], Unmodifiable, lang.Final):
|
|
|
159
159
|
def __lt__(self, other: ta.Any) -> bool:
|
|
160
160
|
return self._target < other
|
|
161
161
|
|
|
162
|
-
def __ne__(self, o:
|
|
162
|
+
def __ne__(self, o: object) -> bool:
|
|
163
163
|
return self._target != o
|
|
164
164
|
|
|
165
165
|
def get(self, k: K, default=None) -> V | None: # type: ignore
|
omlish/collections/utils.py
CHANGED
|
@@ -18,7 +18,7 @@ def mut_toposort(data: dict[T, set[T]]) -> ta.Iterator[set[T]]:
|
|
|
18
18
|
extra_items_in_deps = functools.reduce(set.union, data.values()) - set(data.keys())
|
|
19
19
|
data.update({item: set() for item in extra_items_in_deps})
|
|
20
20
|
while True:
|
|
21
|
-
ordered =
|
|
21
|
+
ordered = {item for item, dep in data.items() if not dep}
|
|
22
22
|
if not ordered:
|
|
23
23
|
break
|
|
24
24
|
yield ordered
|
omlish/configs/flattening.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import abc
|
|
2
|
+
import itertools
|
|
2
3
|
import typing as ta
|
|
3
4
|
|
|
4
5
|
from .. import check
|
|
@@ -34,10 +35,10 @@ class Flattening:
|
|
|
34
35
|
self._index_close = check.not_empty(index_close)
|
|
35
36
|
|
|
36
37
|
def flatten(self, unflattened: StrMap) -> StrMap:
|
|
37
|
-
def rec(prefix:
|
|
38
|
+
def rec(prefix: list[str], value: ta.Any) -> None:
|
|
38
39
|
if isinstance(value, dict):
|
|
39
40
|
for k, v in value.items():
|
|
40
|
-
rec(prefix
|
|
41
|
+
rec([*prefix, k], v)
|
|
41
42
|
elif isinstance(value, list):
|
|
42
43
|
check.not_empty(prefix)
|
|
43
44
|
for i, v in enumerate(value):
|
|
@@ -48,7 +49,7 @@ class Flattening:
|
|
|
48
49
|
raise KeyError(k)
|
|
49
50
|
ret[k] = value
|
|
50
51
|
|
|
51
|
-
ret:
|
|
52
|
+
ret: dict[str, ta.Any] = {}
|
|
52
53
|
rec([], unflattened)
|
|
53
54
|
return ret
|
|
54
55
|
|
|
@@ -83,7 +84,7 @@ class Flattening:
|
|
|
83
84
|
def __init__(self) -> None:
|
|
84
85
|
super().__init__()
|
|
85
86
|
|
|
86
|
-
self._dict:
|
|
87
|
+
self._dict: dict[str, ta.Any] = {}
|
|
87
88
|
|
|
88
89
|
def get(self, key: str) -> ta.Any:
|
|
89
90
|
return self._dict.get(key, _MISSING)
|
|
@@ -100,7 +101,7 @@ class Flattening:
|
|
|
100
101
|
def __init__(self) -> None:
|
|
101
102
|
super().__init__()
|
|
102
103
|
|
|
103
|
-
self._list:
|
|
104
|
+
self._list: list[ta.Any] = []
|
|
104
105
|
|
|
105
106
|
def get(self, key: int) -> ta.Any:
|
|
106
107
|
check.arg(key >= 0)
|
|
@@ -135,7 +136,7 @@ class Flattening:
|
|
|
135
136
|
for fk, v in flattened.items():
|
|
136
137
|
node: Flattening.UnflattenNode = root
|
|
137
138
|
fks = list(split_keys(fk))
|
|
138
|
-
for key, nkey in
|
|
139
|
+
for key, nkey in itertools.pairwise(fks):
|
|
139
140
|
if isinstance(nkey, str):
|
|
140
141
|
node = node.setdefault(key, Flattening.UnflattenDict)
|
|
141
142
|
elif isinstance(nkey, int):
|
omlish/configs/props.py
CHANGED
|
@@ -19,8 +19,8 @@ def escape(token: str) -> str:
|
|
|
19
19
|
return _ESCAPE_PATTERN.sub(r'\\\1', token)
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
def parse_line(line: str) ->
|
|
23
|
-
if line and not
|
|
22
|
+
def parse_line(line: str) -> tuple[str, str] | None:
|
|
23
|
+
if line and not line.startswith(('#', '!')):
|
|
24
24
|
match = _SEPARATOR_PATTERN.search(line)
|
|
25
25
|
if match:
|
|
26
26
|
return normalize(line[:match.start()]), normalize(line[match.end():])
|
|
@@ -54,7 +54,7 @@ def coalesce_lines(lines: ta.Iterable[str]) -> ta.Generator[str, None, None]:
|
|
|
54
54
|
pass
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
def parse_lines(lines: ta.Iterable[str]) ->
|
|
57
|
+
def parse_lines(lines: ta.Iterable[str]) -> dict[str, str]:
|
|
58
58
|
props = {}
|
|
59
59
|
for line in coalesce_lines(lines):
|
|
60
60
|
kv_pair = parse_line(line)
|
omlish/dataclasses/__init__.py
CHANGED
|
@@ -4,5 +4,21 @@ TODO:
|
|
|
4
4
|
- cleanup confer
|
|
5
5
|
- descriptors - check_type/validators don't handle setters lol
|
|
6
6
|
- deep_frozen?
|
|
7
|
-
-
|
|
7
|
+
- field:
|
|
8
|
+
- frozen
|
|
9
|
+
- pickle/transient
|
|
10
|
+
- mangled
|
|
11
|
+
- doc
|
|
12
|
+
- derive
|
|
13
|
+
- check_type
|
|
14
|
+
- class
|
|
15
|
+
- strict_eq
|
|
16
|
+
- allow_setattr
|
|
17
|
+
- mangler
|
|
18
|
+
- observable
|
|
19
|
+
- c/py gen
|
|
20
|
+
- iterable
|
|
21
|
+
- proto/jsonschema gen
|
|
22
|
+
- enums
|
|
23
|
+
- nodal
|
|
8
24
|
"""
|
omlish/dataclasses/impl/api.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import collections.abc
|
|
2
|
+
import contextlib
|
|
2
3
|
import dataclasses as dc
|
|
3
4
|
import keyword
|
|
4
5
|
import sys
|
|
@@ -18,13 +19,13 @@ from .params import ParamsExtras
|
|
|
18
19
|
MISSING = dc.MISSING
|
|
19
20
|
|
|
20
21
|
|
|
21
|
-
def field(
|
|
22
|
+
def field( # noqa
|
|
22
23
|
default=MISSING,
|
|
23
24
|
*,
|
|
24
25
|
default_factory=MISSING,
|
|
25
26
|
init=True,
|
|
26
|
-
repr=True,
|
|
27
|
-
hash=None,
|
|
27
|
+
repr=True, # noqa
|
|
28
|
+
hash=None, # noqa
|
|
28
29
|
compare=True,
|
|
29
30
|
metadata=None,
|
|
30
31
|
kw_only=MISSING,
|
|
@@ -66,12 +67,12 @@ def _strip_missing_values(d):
|
|
|
66
67
|
return {k: v for k, v in d.items() if v is not MISSING}
|
|
67
68
|
|
|
68
69
|
|
|
69
|
-
def dataclass(
|
|
70
|
+
def dataclass( # noqa
|
|
70
71
|
cls=None,
|
|
71
72
|
/,
|
|
72
73
|
*,
|
|
73
74
|
init=True,
|
|
74
|
-
repr=True,
|
|
75
|
+
repr=True, # noqa
|
|
75
76
|
eq=True,
|
|
76
77
|
order=False,
|
|
77
78
|
unsafe_hash=False,
|
|
@@ -135,14 +136,14 @@ def dataclass(
|
|
|
135
136
|
return wrap(cls)
|
|
136
137
|
|
|
137
138
|
|
|
138
|
-
def make_dataclass(
|
|
139
|
+
def make_dataclass( # noqa
|
|
139
140
|
cls_name,
|
|
140
141
|
fields,
|
|
141
142
|
*,
|
|
142
143
|
bases=(),
|
|
143
144
|
namespace=None,
|
|
144
145
|
init=True,
|
|
145
|
-
repr=True,
|
|
146
|
+
repr=True, # noqa
|
|
146
147
|
eq=True,
|
|
147
148
|
order=False,
|
|
148
149
|
unsafe_hash=False,
|
|
@@ -195,10 +196,8 @@ def make_dataclass(
|
|
|
195
196
|
try:
|
|
196
197
|
module = sys._getframemodulename(1) or '__main__' # type: ignore # noqa
|
|
197
198
|
except AttributeError:
|
|
198
|
-
|
|
199
|
+
with contextlib.suppress(AttributeError, ValueError):
|
|
199
200
|
module = sys._getframe(1).f_globals.get('__name__', '__main__') # noqa
|
|
200
|
-
except (AttributeError, ValueError):
|
|
201
|
-
pass
|
|
202
201
|
if module is not None:
|
|
203
202
|
cls.__module__ = module
|
|
204
203
|
|
|
@@ -225,7 +224,7 @@ class _ExtraParamsKwargs:
|
|
|
225
224
|
pass
|
|
226
225
|
|
|
227
226
|
|
|
228
|
-
def extra_params(
|
|
227
|
+
def extra_params( # noqa
|
|
229
228
|
*,
|
|
230
229
|
reorder=MISSING,
|
|
231
230
|
cache_hash=MISSING,
|
omlish/dataclasses/impl/as_.py
CHANGED
|
@@ -5,9 +5,9 @@ from .internals import is_dataclass_instance
|
|
|
5
5
|
from .internals import ATOMIC_TYPES
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
def asdict(obj, *, dict_factory=dict):
|
|
8
|
+
def asdict(obj, *, dict_factory=dict): # noqa
|
|
9
9
|
if not is_dataclass_instance(obj): # noqa
|
|
10
|
-
raise TypeError(
|
|
10
|
+
raise TypeError('asdict() should be called on dataclass instances')
|
|
11
11
|
return _asdict_inner(obj, dict_factory)
|
|
12
12
|
|
|
13
13
|
|
|
@@ -40,9 +40,9 @@ def _asdict_inner(obj, dict_factory):
|
|
|
40
40
|
return copy.deepcopy(obj)
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
def astuple(obj, *, tuple_factory=tuple):
|
|
43
|
+
def astuple(obj, *, tuple_factory=tuple): # noqa
|
|
44
44
|
if not is_dataclass_instance(obj):
|
|
45
|
-
raise TypeError(
|
|
45
|
+
raise TypeError('astuple() should be called on dataclass instances')
|
|
46
46
|
return _astuple_inner(obj, tuple_factory)
|
|
47
47
|
|
|
48
48
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class
|
|
1
|
+
class CheckError(Exception):
|
|
2
2
|
pass
|
|
@@ -55,7 +55,7 @@ def preprocess_field(
|
|
|
55
55
|
if ft in (FieldType.CLASS, FieldType.INIT):
|
|
56
56
|
if f.default_factory is not MISSING:
|
|
57
57
|
raise TypeError(f'field {f.name} cannot have a default factory')
|
|
58
|
-
f._field_type = ft.value # type: ignore
|
|
58
|
+
f._field_type = ft.value # type: ignore # noqa
|
|
59
59
|
|
|
60
60
|
if ft in (FieldType.INSTANCE, FieldType.INIT):
|
|
61
61
|
if f.kw_only is MISSING:
|
|
@@ -88,7 +88,7 @@ def field_assign(
|
|
|
88
88
|
def field_init(
|
|
89
89
|
f: dc.Field,
|
|
90
90
|
frozen: bool,
|
|
91
|
-
locals: dict[str, ta.Any],
|
|
91
|
+
locals: dict[str, ta.Any], # noqa
|
|
92
92
|
self_name: str,
|
|
93
93
|
slots: bool,
|
|
94
94
|
) -> ta.Sequence[str]:
|
|
@@ -135,12 +135,12 @@ def field_init(
|
|
|
135
135
|
locals[default_name] = f.default
|
|
136
136
|
value = f.name
|
|
137
137
|
|
|
138
|
+
elif slots and f.default is not MISSING:
|
|
139
|
+
locals[default_name] = f.default
|
|
140
|
+
value = default_name
|
|
141
|
+
|
|
138
142
|
else:
|
|
139
|
-
|
|
140
|
-
locals[default_name] = f.default
|
|
141
|
-
value = default_name
|
|
142
|
-
else:
|
|
143
|
-
pass
|
|
143
|
+
pass
|
|
144
144
|
|
|
145
145
|
if value is not None and field_type(f) is not FieldType.INIT:
|
|
146
146
|
lines.append(field_assign(frozen, f.name, value, self_name, fx.override)) # noqa
|
|
@@ -10,9 +10,9 @@ from .utils import set_new_attribute
|
|
|
10
10
|
def frozen_get_del_attr(
|
|
11
11
|
cls: type,
|
|
12
12
|
fields: ta.Sequence[dc.Field],
|
|
13
|
-
globals: Namespace,
|
|
13
|
+
globals: Namespace, # noqa
|
|
14
14
|
) -> tuple[ta.Callable, ta.Callable]:
|
|
15
|
-
locals = {
|
|
15
|
+
locals = { # noqa
|
|
16
16
|
'cls': cls,
|
|
17
17
|
'FrozenInstanceError': dc.FrozenInstanceError,
|
|
18
18
|
}
|
omlish/dataclasses/impl/init.py
CHANGED
|
@@ -3,7 +3,7 @@ import inspect
|
|
|
3
3
|
import typing as ta
|
|
4
4
|
|
|
5
5
|
from ... import lang
|
|
6
|
-
from .exceptions import
|
|
6
|
+
from .exceptions import CheckError
|
|
7
7
|
from .fields import field_init
|
|
8
8
|
from .fields import field_type
|
|
9
9
|
from .fields import has_default
|
|
@@ -64,7 +64,7 @@ class InitBuilder:
|
|
|
64
64
|
fields: ta.Mapping[str, dc.Field],
|
|
65
65
|
has_post_init: bool,
|
|
66
66
|
self_name: str,
|
|
67
|
-
globals: Namespace,
|
|
67
|
+
globals: Namespace, # noqa
|
|
68
68
|
) -> None:
|
|
69
69
|
super().__init__()
|
|
70
70
|
|
|
@@ -86,7 +86,7 @@ class InitBuilder:
|
|
|
86
86
|
elif seen_default:
|
|
87
87
|
raise TypeError(f'non-default argument {f.name!r} follows default argument {seen_default.name!r}')
|
|
88
88
|
|
|
89
|
-
locals: dict[str, ta.Any] = {}
|
|
89
|
+
locals: dict[str, ta.Any] = {} # noqa
|
|
90
90
|
|
|
91
91
|
if self._info.params_extras.generic_init:
|
|
92
92
|
get_fty = lambda f: self._info.generic_replaced_field_annotations[f.name]
|
|
@@ -99,7 +99,7 @@ class InitBuilder:
|
|
|
99
99
|
'__dataclass_builtins_object__': object,
|
|
100
100
|
'__dataclass_builtins_isinstance__': isinstance,
|
|
101
101
|
'__dataclass_builtins_TypeError__': TypeError,
|
|
102
|
-
'__dataclass_CheckException__':
|
|
102
|
+
'__dataclass_CheckException__': CheckError,
|
|
103
103
|
})
|
|
104
104
|
|
|
105
105
|
body_lines: list[str] = []
|
|
@@ -143,7 +143,7 @@ class InitBuilder:
|
|
|
143
143
|
|
|
144
144
|
return create_fn(
|
|
145
145
|
'__init__',
|
|
146
|
-
[self._self_name
|
|
146
|
+
[self._self_name, *_init_params],
|
|
147
147
|
body_lines,
|
|
148
148
|
locals=locals,
|
|
149
149
|
globals=self._globals,
|
omlish/dataclasses/impl/order.py
CHANGED
|
@@ -11,7 +11,7 @@ from .utils import set_new_attribute
|
|
|
11
11
|
MISSING = dc.MISSING
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
def replace(obj, /, **changes):
|
|
14
|
+
def replace(obj, /, **changes): # noqa
|
|
15
15
|
if not is_dataclass_instance(obj):
|
|
16
16
|
raise TypeError('replace() should be called on dataclass instances')
|
|
17
17
|
return _replace(obj, **changes)
|
omlish/dataclasses/impl/repr.py
CHANGED
|
@@ -11,9 +11,9 @@ from .utils import set_new_attribute
|
|
|
11
11
|
|
|
12
12
|
def repr_fn(
|
|
13
13
|
fields: ta.Sequence[dc.Field],
|
|
14
|
-
globals: Namespace,
|
|
14
|
+
globals: Namespace, # noqa
|
|
15
15
|
) -> ta.Callable:
|
|
16
|
-
locals: dict[str, ta.Any] = {}
|
|
16
|
+
locals: dict[str, ta.Any] = {} # noqa
|
|
17
17
|
if any(get_field_extras(f).repr_fn is not None for f in fields):
|
|
18
18
|
lst: list[str] = []
|
|
19
19
|
for f in fields:
|
|
@@ -25,12 +25,12 @@ def repr_fn(
|
|
|
25
25
|
src = [
|
|
26
26
|
'l = []',
|
|
27
27
|
*lst,
|
|
28
|
-
'return f"{self.__class__.__qualname__}({
|
|
28
|
+
'return f"{self.__class__.__qualname__}({", ".join(l)})"',
|
|
29
29
|
]
|
|
30
30
|
else:
|
|
31
31
|
src = [
|
|
32
32
|
'return f"{self.__class__.__qualname__}(' +
|
|
33
|
-
', '.join([f
|
|
33
|
+
', '.join([f'{f.name}={{self.{f.name}!r}}' for f in fields]) +
|
|
34
34
|
')"',
|
|
35
35
|
]
|
|
36
36
|
fn = create_fn(
|
omlish/dataclasses/impl/utils.py
CHANGED
|
@@ -16,15 +16,15 @@ def create_fn(
|
|
|
16
16
|
args: ta.Sequence[str],
|
|
17
17
|
body: ta.Sequence[str],
|
|
18
18
|
*,
|
|
19
|
-
globals: Namespace | None = None,
|
|
20
|
-
locals: Namespace | None = None,
|
|
19
|
+
globals: Namespace | None = None, # noqa
|
|
20
|
+
locals: Namespace | None = None, # noqa
|
|
21
21
|
return_type: lang.Maybe[ta.Any] = lang.empty(),
|
|
22
22
|
) -> ta.Callable:
|
|
23
23
|
check.not_isinstance(args, str)
|
|
24
24
|
check.not_isinstance(body, str)
|
|
25
25
|
|
|
26
26
|
if locals is None:
|
|
27
|
-
locals = {}
|
|
27
|
+
locals = {} # noqa
|
|
28
28
|
return_annotation = ''
|
|
29
29
|
if return_type.present:
|
|
30
30
|
locals['__dataclass_return_type__'] = return_type()
|
|
@@ -43,7 +43,7 @@ def create_fn(
|
|
|
43
43
|
|
|
44
44
|
# TODO: https://github.com/python/cpython/commit/8945b7ff55b87d11c747af2dad0e3e4d631e62d6
|
|
45
45
|
class FuncBuilder:
|
|
46
|
-
def __init__(self, globals: Namespace) -> None:
|
|
46
|
+
def __init__(self, globals: Namespace) -> None: # noqa
|
|
47
47
|
super().__init__()
|
|
48
48
|
|
|
49
49
|
self.names: list[str] = []
|
|
@@ -59,7 +59,7 @@ class FuncBuilder:
|
|
|
59
59
|
args: ta.Sequence[str],
|
|
60
60
|
body: ta.Sequence[str],
|
|
61
61
|
*,
|
|
62
|
-
locals: Namespace | None = None,
|
|
62
|
+
locals: Namespace | None = None, # noqa
|
|
63
63
|
return_type: lang.Maybe[ta.Any] = lang.empty(),
|
|
64
64
|
overwrite_error: bool = False,
|
|
65
65
|
unconditional_add: bool = False,
|
|
@@ -91,7 +91,7 @@ class FuncBuilder:
|
|
|
91
91
|
body = textwrap.indent('\n'.join(body), ' ')
|
|
92
92
|
|
|
93
93
|
# Compute the text of the entire function, add it to the text we're generating.
|
|
94
|
-
deco_str =
|
|
94
|
+
deco_str = ' {decorator}\n' if decorator else ''
|
|
95
95
|
self.src.append(f'{deco_str} def {name}({args}){return_annotation}:\n{body}')
|
|
96
96
|
|
|
97
97
|
def add_fns_to_class(self, cls: type) -> None:
|