omlish 0.0.0.dev249__py3-none-any.whl → 0.0.0.dev250__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.
omlish/__about__.py CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev249'
2
- __revision__ = '0ad7e21d0ef610493354b1fbd22f7c3be5fc9bea'
1
+ __version__ = '0.0.0.dev250'
2
+ __revision__ = '0e6e1316b474c6f882784e2474e809a478c54732'
3
3
 
4
4
 
5
5
  #
omlish/lang/__init__.py CHANGED
@@ -217,8 +217,8 @@ from .params import ( # noqa
217
217
  ParamSeparator,
218
218
  ParamSpec,
219
219
  PosOnlyParam,
220
- ValueParam,
221
- VariadicParam,
220
+ ValParam,
221
+ VarParam,
222
222
  param_render,
223
223
  )
224
224
 
@@ -24,7 +24,7 @@ from ..params import KwargsParam
24
24
  from ..params import Param
25
25
  from ..params import ParamSeparator
26
26
  from ..params import ParamSpec
27
- from ..params import ValueParam
27
+ from ..params import ValParam
28
28
  from ..params import param_render
29
29
 
30
30
 
@@ -52,7 +52,7 @@ _PRE_MADE_CACHE_KEY_MAKERS = [
52
52
 
53
53
 
54
54
  _PRE_MADE_CACHE_KEY_MAKERS_BY_PARAM_SPEC: ta.Mapping[ParamSpec, CacheKeyMaker] = {
55
- ParamSpec.of_signature(inspect.signature(fn)): fn # type: ignore
55
+ ParamSpec.inspect(fn): fn # type: ignore
56
56
  for fn in _PRE_MADE_CACHE_KEY_MAKERS
57
57
  }
58
58
 
@@ -68,8 +68,8 @@ def _make_unwrapped_cache_key_maker(
68
68
  if inspect.isgeneratorfunction(fn) or inspect.iscoroutinefunction(fn):
69
69
  raise TypeError(fn)
70
70
 
71
- ps = ParamSpec.of_signature(
72
- inspect.signature(fn),
71
+ ps = ParamSpec.inspect(
72
+ fn,
73
73
  offset=1 if bound else 0,
74
74
  strip_annotations=True,
75
75
  )
@@ -100,7 +100,7 @@ def _make_unwrapped_cache_key_maker(
100
100
  if not isinstance(p, Param):
101
101
  raise TypeError(p)
102
102
 
103
- if isinstance(p, ValueParam) and p.default.present:
103
+ if isinstance(p, ValParam) and p.default.present:
104
104
  ns[p.name] = p.default
105
105
 
106
106
  src_params.append(param_render(
omlish/lang/params.py CHANGED
@@ -21,10 +21,12 @@ T = ta.TypeVar('T')
21
21
  ##
22
22
 
23
23
 
24
- @dc.dataclass(frozen=True)
24
+ @dc.dataclass(frozen=True, unsafe_hash=True)
25
25
  class Param(Sealed, Abstract):
26
26
  name: str
27
27
 
28
+ annotation: Maybe = empty()
29
+
28
30
  prefix: ta.ClassVar[str] = ''
29
31
 
30
32
  @property
@@ -35,18 +37,18 @@ class Param(Sealed, Abstract):
35
37
  #
36
38
 
37
39
 
38
- @dc.dataclass(frozen=True)
39
- class VariadicParam(Param, Abstract):
40
- annotation: Maybe = empty()
40
+ @dc.dataclass(frozen=True, unsafe_hash=True)
41
+ class VarParam(Param, Abstract):
42
+ pass
41
43
 
42
44
 
43
- @dc.dataclass(frozen=True)
44
- class ArgsParam(VariadicParam, Final):
45
+ @dc.dataclass(frozen=True, unsafe_hash=True)
46
+ class ArgsParam(VarParam, Final):
45
47
  prefix: ta.ClassVar[str] = '*'
46
48
 
47
49
 
48
- @dc.dataclass(frozen=True)
49
- class KwargsParam(VariadicParam, Final):
50
+ @dc.dataclass(frozen=True, unsafe_hash=True)
51
+ class KwargsParam(VarParam, Final):
50
52
  prefix: ta.ClassVar[str] = '**'
51
53
 
52
54
 
@@ -54,18 +56,17 @@ class KwargsParam(VariadicParam, Final):
54
56
 
55
57
 
56
58
  @dc.dataclass(frozen=True, unsafe_hash=True)
57
- class ValueParam(Param):
59
+ class ValParam(Param):
58
60
  default: Maybe = empty()
59
- annotation: Maybe = empty()
60
61
 
61
62
 
62
63
  @dc.dataclass(frozen=True, unsafe_hash=True)
63
- class PosOnlyParam(ValueParam, Final):
64
+ class PosOnlyParam(ValParam, Final):
64
65
  pass
65
66
 
66
67
 
67
68
  @dc.dataclass(frozen=True, unsafe_hash=True)
68
- class KwOnlyParam(ValueParam, Final):
69
+ class KwOnlyParam(ValParam, Final):
69
70
  pass
70
71
 
71
72
 
@@ -95,8 +96,8 @@ class ParamSpec(ta.Sequence[Param], Final):
95
96
 
96
97
  self._hash: int | None = None
97
98
 
98
- self._has_defaults: bool | None = None
99
99
  self._has_annotations: bool | None = None
100
+ self._has_defaults: bool | None = None
100
101
 
101
102
  self._with_seps: tuple[Param | ParamSeparator, ...] | None = None
102
103
 
@@ -108,8 +109,8 @@ class ParamSpec(ta.Sequence[Param], Final):
108
109
  sig: inspect.Signature,
109
110
  *,
110
111
  offset: int = 0,
111
- strip_defaults: bool = False,
112
112
  strip_annotations: bool = False,
113
+ strip_defaults: bool = False,
113
114
  ) -> 'ParamSpec':
114
115
  ps: list[Param] = []
115
116
 
@@ -118,29 +119,40 @@ class ParamSpec(ta.Sequence[Param], Final):
118
119
  if i < offset:
119
120
  continue
120
121
 
121
- dfl = _inspect_empty_to_maybe(ip.default) if not strip_defaults else empty()
122
122
  ann = _inspect_empty_to_maybe(ip.annotation) if not strip_annotations else empty()
123
+ dfl = _inspect_empty_to_maybe(ip.default) if not strip_defaults else empty()
123
124
 
124
125
  if ip.kind == inspect.Parameter.POSITIONAL_ONLY:
125
- ps.append(PosOnlyParam(ip.name, dfl, ann))
126
+ ps.append(PosOnlyParam(ip.name, ann, dfl))
126
127
 
127
128
  elif ip.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD:
128
- ps.append(ValueParam(ip.name, dfl, ann))
129
+ ps.append(ValParam(ip.name, ann, dfl))
129
130
 
130
131
  elif ip.kind == inspect.Parameter.VAR_POSITIONAL:
131
- ps.append(ArgsParam(ip.name))
132
-
133
- elif ip.kind == inspect.Parameter.VAR_KEYWORD:
134
- ps.append(KwargsParam(ip.name))
132
+ ps.append(ArgsParam(ip.name, ann))
135
133
 
136
134
  elif ip.kind == inspect.Parameter.KEYWORD_ONLY:
137
- ps.append(KwOnlyParam(ip.name, dfl, ann))
135
+ ps.append(KwOnlyParam(ip.name, ann, dfl))
136
+
137
+ elif ip.kind == inspect.Parameter.VAR_KEYWORD:
138
+ ps.append(KwargsParam(ip.name, ann))
138
139
 
139
140
  else:
140
141
  raise ValueError(ip.kind)
141
142
 
142
143
  return cls(*ps)
143
144
 
145
+ @classmethod
146
+ def inspect(
147
+ cls,
148
+ obj: ta.Any,
149
+ **kwargs: ta.Any,
150
+ ) -> 'ParamSpec':
151
+ return cls.of_signature(
152
+ inspect.signature(obj),
153
+ **kwargs,
154
+ )
155
+
144
156
  #
145
157
 
146
158
  def __repr__(self) -> str:
@@ -159,26 +171,26 @@ class ParamSpec(ta.Sequence[Param], Final):
159
171
 
160
172
  #
161
173
 
174
+ @property
175
+ def has_annotations(self) -> bool:
176
+ if (ha := self._has_annotations) is not None:
177
+ return ha
178
+ self._has_annotations = ha = any(
179
+ isinstance(p, (VarParam, ValParam)) and p.annotation.present
180
+ for p in self._ps
181
+ )
182
+ return ha
183
+
162
184
  @property
163
185
  def has_defaults(self) -> bool:
164
186
  if (hd := self._has_defaults) is not None:
165
187
  return hd
166
188
  self._has_defaults = hd = any(
167
- isinstance(p, ValueParam) and p.default.present
189
+ isinstance(p, ValParam) and p.default.present
168
190
  for p in self._ps
169
191
  )
170
192
  return hd
171
193
 
172
- @property
173
- def has_annotations(self) -> bool:
174
- if (ha := self._has_defaults) is not None:
175
- return ha
176
- self._has_annotations = ha = any(
177
- isinstance(p, (VariadicParam, ValueParam)) and p.annotation.present
178
- for p in self._ps
179
- )
180
- return ha
181
-
182
194
  #
183
195
 
184
196
  @property
@@ -228,22 +240,22 @@ class ParamSpec(ta.Sequence[Param], Final):
228
240
  def param_render(
229
241
  p: Param | ParamSeparator,
230
242
  *,
231
- render_default: ta.Callable[[ta.Any], str] | None = None,
232
243
  render_annotation: ta.Callable[[ta.Any], str] | None = None,
244
+ render_default: ta.Callable[[ta.Any], str] | None = None,
233
245
  ) -> str:
234
246
  if isinstance(p, Param):
235
247
  dfl_s: str | None = None
236
- if isinstance(p, ValueParam) and p.default.present:
237
- if render_default is None:
238
- raise ValueError(f'Param {p.name} has a default but no default renderer provided')
239
- dfl_s = render_default(p.default.must())
240
-
241
248
  ann_s: str | None = None
242
- if isinstance(p, (VariadicParam, ValueParam)) and p.annotation.present:
249
+ if isinstance(p, (VarParam, ValParam)) and p.annotation.present:
243
250
  if render_annotation is None:
244
251
  raise ValueError(f'Param {p.name} has an annotation but no annotation renderer provided')
245
252
  ann_s = render_annotation(p.annotation.must())
246
253
 
254
+ if isinstance(p, ValParam) and p.default.present:
255
+ if render_default is None:
256
+ raise ValueError(f'Param {p.name} has a default but no default renderer provided')
257
+ dfl_s = render_default(p.default.must())
258
+
247
259
  if ann_s is not None:
248
260
  if dfl_s is not None:
249
261
  return f'{p.name_with_prefix}: {ann_s} = {dfl_s}'
omlish/lang/resources.py CHANGED
@@ -1,9 +1,19 @@
1
1
  import dataclasses as dc
2
2
  import functools
3
- import importlib.resources
4
3
  import os.path
5
4
  import typing as ta
6
5
 
6
+ from .imports import proxy_import
7
+
8
+
9
+ if ta.TYPE_CHECKING:
10
+ import importlib.resources as importlib_resources
11
+ else:
12
+ importlib_resources = proxy_import('importlib.resources')
13
+
14
+
15
+ ##
16
+
7
17
 
8
18
  @dc.dataclass(frozen=True)
9
19
  class ReadableResource:
@@ -18,7 +28,7 @@ class ReadableResource:
18
28
  def get_package_resources(anchor: str) -> ta.Mapping[str, ReadableResource]:
19
29
  lst: list[ReadableResource] = []
20
30
 
21
- for pf in importlib.resources.files(anchor).iterdir():
31
+ for pf in importlib_resources.files(anchor).iterdir():
22
32
  lst.append(ReadableResource(
23
33
  name=pf.name,
24
34
  is_file=pf.is_file(),
@@ -65,7 +75,7 @@ def get_relative_resources(
65
75
  if num_up:
66
76
  pkg_parts = pkg_parts[:-num_up]
67
77
  anchor = '.'.join([*pkg_parts, *path_parts])
68
- for pf in importlib.resources.files(anchor).iterdir():
78
+ for pf in importlib_resources.files(anchor).iterdir():
69
79
  lst.append(ReadableResource(
70
80
  name=pf.name,
71
81
  is_file=pf.is_file(),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: omlish
3
- Version: 0.0.0.dev249
3
+ Version: 0.0.0.dev250
4
4
  Summary: omlish
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -1,5 +1,5 @@
1
1
  omlish/.manifests.json,sha256=x26AIwDzScUvnX-p4xlq6Zc5QYrAo0Vmgf1qHc1KL_M,8253
2
- omlish/__about__.py,sha256=PjdfPdJQSIUlnk8M2lh4cIvBDuBsym-PBbz4Y6tueh4,3380
2
+ omlish/__about__.py,sha256=LCIKYHw0FYdPvCdmhqyF7FaJsL17sOU3m3dX5HFBUbg,3380
3
3
  omlish/__init__.py,sha256=SsyiITTuK0v74XpKV8dqNaCmjOlan1JZKrHQv5rWKPA,253
4
4
  omlish/c3.py,sha256=ubu7lHwss5V4UznbejAI0qXhXahrU01MysuHOZI9C4U,8116
5
5
  omlish/cached.py,sha256=MLap_p0rdGoDIMVhXVHm1tsbcWobJF0OanoodV03Ju8,542
@@ -400,7 +400,7 @@ omlish/iterators/iterators.py,sha256=iTQQwBE6Wzoy36dnbPIws17zbjE3zNN4KwVw4Fzh-gY
400
400
  omlish/iterators/recipes.py,sha256=53mkexitMhkwXQZbL6DrhpT0WePQ_56uXd5Jaw3DfzI,467
401
401
  omlish/iterators/tools.py,sha256=Pi4ybXytUXVZ3xwK89xpPImQfYYId9p1vIFQvVqVLqA,2551
402
402
  omlish/iterators/unique.py,sha256=0jAX3kwzVfRNhe0Tmh7kVP_Q2WBIn8POo_O-rgFV0rQ,1390
403
- omlish/lang/__init__.py,sha256=Az9r0956Gc4tdqdrkQholNkiR5W4lMazHILuHGupig0,4899
403
+ omlish/lang/__init__.py,sha256=TKxKq0L7Q34kdV0_UcxC81Umx64Uz_TPUgH6cy7Uzck,4892
404
404
  omlish/lang/attrs.py,sha256=fofCKN0X8TMu1yGqHpLpNLih9r9HWl3D3Vn3b6O791w,3891
405
405
  omlish/lang/clsdct.py,sha256=sJYadm-fwzti-gsi98knR5qQUxriBmOqQE_qz3RopNk,1743
406
406
  omlish/lang/cmp.py,sha256=5vbzWWbqdzDmNKAGL19z6ZfUKe5Ci49e-Oegf9f4BsE,1346
@@ -415,14 +415,14 @@ omlish/lang/imports.py,sha256=Gdl6xCF89xiMOE1yDmdvKWamLq8HX-XPianO58Jdpmw,9218
415
415
  omlish/lang/iterables.py,sha256=HOjcxOwyI5bBApDLsxRAGGhTTmw7fdZl2kEckxRVl-0,1994
416
416
  omlish/lang/maybes.py,sha256=dAgrUoAhCgyrHRqa73CkaGnpXwGc-o9n-NIThrNXnbU,3416
417
417
  omlish/lang/objects.py,sha256=65XsD7UtblRdNe2ID1-brn_QvRkJhBIk5nyZWcQNeqU,4574
418
- omlish/lang/params.py,sha256=ojzyfao5e8tdBjJD57WWlipfh-5PV4Y0bLAcniflCRU,6436
418
+ omlish/lang/params.py,sha256=AaUHI59qBLV7I-q1qPIEPTKGvgXzSRsmkNR2jTma5ZY,6688
419
419
  omlish/lang/resolving.py,sha256=OuN2mDTPNyBUbcrswtvFKtj4xgH4H4WglgqSKv3MTy0,1606
420
- omlish/lang/resources.py,sha256=N64KeVE-rYMxqBBRp91qzgVqpOVR2uX7k1WlS_bo5hM,2681
420
+ omlish/lang/resources.py,sha256=WKkAddC3ctMK1bvGw-elGe8ZxAj2IaUTKVSu2nfgHTo,2839
421
421
  omlish/lang/strings.py,sha256=egdv8PxLNG40-5V93agP5j2rBUDIsahCx048zV7uEbU,4690
422
422
  omlish/lang/sys.py,sha256=UoZz_PJYVKLQAKqYxxn-LHz1okK_38I__maZgnXMcxU,406
423
423
  omlish/lang/typing.py,sha256=Zdad9Zv0sa-hIaUXPrzPidT7sDVpRcussAI7D-j-I1c,3296
424
424
  omlish/lang/cached/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
425
- omlish/lang/cached/function.py,sha256=00ChRDuDv3n6IRYTumKz7d-nA5pVzTHAWlaZfopeyQw,9240
425
+ omlish/lang/cached/function.py,sha256=3AeTVfpzovMMWbnjFuT5mM7kT1dBuk7fa66FOJKikYw,9188
426
426
  omlish/lang/cached/property.py,sha256=kzbao_35PlszdK_9oJBWrMmFFlVK_Xhx7YczHhTJ6cc,2764
427
427
  omlish/lang/classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
428
428
  omlish/lang/classes/abstract.py,sha256=bIcuAetV_aChhpSURypmjjcqP07xi20uVYPKh1kvQNU,3710
@@ -735,9 +735,9 @@ omlish/text/mangle.py,sha256=kfzFLfvepH-chl1P89_mdc5vC4FSqyPA2aVtgzuB8IY,1133
735
735
  omlish/text/minja.py,sha256=jZC-fp3Xuhx48ppqsf2Sf1pHbC0t8XBB7UpUUoOk2Qw,5751
736
736
  omlish/text/parts.py,sha256=JkNZpyR2tv2CNcTaWJJhpQ9E4F0yPR8P_YfDbZfMtwQ,6182
737
737
  omlish/text/random.py,sha256=jNWpqiaKjKyTdMXC-pWAsSC10AAP-cmRRPVhm59ZWLk,194
738
- omlish-0.0.0.dev249.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
739
- omlish-0.0.0.dev249.dist-info/METADATA,sha256=3WFq8RmEWWOgGChudW07i3DErPgEqz2rPmH343HgkYo,4176
740
- omlish-0.0.0.dev249.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
741
- omlish-0.0.0.dev249.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
742
- omlish-0.0.0.dev249.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
743
- omlish-0.0.0.dev249.dist-info/RECORD,,
738
+ omlish-0.0.0.dev250.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
739
+ omlish-0.0.0.dev250.dist-info/METADATA,sha256=I94K5DI1DH2JEs5HA15SkuwlyDsnTF5PYIeSr5rKrGo,4176
740
+ omlish-0.0.0.dev250.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
741
+ omlish-0.0.0.dev250.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
742
+ omlish-0.0.0.dev250.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
743
+ omlish-0.0.0.dev250.dist-info/RECORD,,