dycw-utilities 0.111.0__py3-none-any.whl → 0.111.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-utilities
3
- Version: 0.111.0
3
+ Version: 0.111.1
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=fjbCo5KvSkqKWLmPeMS8U77JZlYaYPd9js1ZVmdD1FE,60
1
+ utilities/__init__.py,sha256=j1-gk7DzQOb2e2RhnLMwpl11AV5CfMKamy2OkF4La18,60
2
2
  utilities/altair.py,sha256=Gpja-flOo-Db0PIPJLJsgzAlXWoKUjPU1qY-DQ829ek,9156
3
3
  utilities/astor.py,sha256=xuDUkjq0-b6fhtwjhbnebzbqQZAjMSHR1IIS5uOodVg,777
4
4
  utilities/asyncio.py,sha256=41oQUurWMvadFK5gFnaG21hMM0Vmfn2WS6OpC0R9mas,14757
@@ -41,7 +41,7 @@ utilities/operator.py,sha256=0M2yZJ0PODH47ogFEnkGMBe_cfxwZR02T_92LZVZvHo,3715
41
41
  utilities/optuna.py,sha256=loyJGWTzljgdJaoLhP09PT8Jz6o_pwBOwehY33lHkhw,1923
42
42
  utilities/orjson.py,sha256=DBm2zPP04kcHpY3l1etL24ksNynu-R3duFyx3U-RjqQ,36948
43
43
  utilities/os.py,sha256=D_FyyT-6TtqiN9KSS7c9g1fnUtgxmyMtzAjmYLkk46A,3587
44
- utilities/parse.py,sha256=-sDMqA4nB4CFctc86uIlSoKmIUisTUd3qyBcuUnf1D0,18957
44
+ utilities/parse.py,sha256=hG-y8WAzpATakA61UOF6UlhfuJQ9XbMN-Uub1ZaiBRU,18780
45
45
  utilities/pathlib.py,sha256=31WPMXdLIyXgYOMMl_HOI2wlo66MGSE-cgeelk-Lias,1410
46
46
  utilities/period.py,sha256=RWfcNVoNlW07RNdU47g_zuLZMKbtgfK4bE6G-9tVjY8,11024
47
47
  utilities/pickle.py,sha256=Bhvd7cZl-zQKQDFjUerqGuSKlHvnW1K2QXeU5UZibtg,657
@@ -87,7 +87,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
87
87
  utilities/whenever.py,sha256=TjoTAJ1R27-rKXiXzdE4GzPidmYqm0W58XydDXp-QZM,17786
88
88
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
89
89
  utilities/zoneinfo.py,sha256=-DQz5a0Ikw9jfSZtL0BEQkXOMC9yGn_xiJYNCLMiqEc,1989
90
- dycw_utilities-0.111.0.dist-info/METADATA,sha256=9UDVxMivd6ye3O57NEI2wEddqVpW9OE_rc_uhtMXD-c,13004
91
- dycw_utilities-0.111.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
92
- dycw_utilities-0.111.0.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
93
- dycw_utilities-0.111.0.dist-info/RECORD,,
90
+ dycw_utilities-0.111.1.dist-info/METADATA,sha256=kXoTkJKsgrfBYD5eCwE45d4mGIX5CMZhVeNHh9SRiL8,13004
91
+ dycw_utilities-0.111.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
92
+ dycw_utilities-0.111.1.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
93
+ dycw_utilities-0.111.1.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.111.0"
3
+ __version__ = "0.111.1"
utilities/parse.py CHANGED
@@ -60,15 +60,15 @@ def parse_object(
60
60
  extra: ParseObjectExtra | None = None,
61
61
  ) -> Any:
62
62
  """Parse text."""
63
+ if extra is not None:
64
+ return _parse_object_extra(type_, text, extra)
63
65
  if type_ is None:
64
66
  try:
65
67
  return parse_none(text)
66
68
  except ParseNoneError:
67
69
  raise _ParseObjectParseError(type_=type_, text=text) from None
68
70
  if isinstance(type_, type):
69
- return _parse_object_type(
70
- type_, text, case_sensitive=case_sensitive, extra=extra
71
- )
71
+ return _parse_object_type(type_, text, case_sensitive=case_sensitive)
72
72
  if is_dict_type(type_):
73
73
  return _parse_object_dict_type(
74
74
  type_,
@@ -146,17 +146,12 @@ def parse_object(
146
146
  extra=extra,
147
147
  )
148
148
  if is_union_type(type_):
149
- return _parse_object_union_type(type_, text, extra=extra)
149
+ return _parse_object_union_type(type_, text)
150
150
  raise _ParseObjectParseError(type_=type_, text=text) from None
151
151
 
152
152
 
153
153
  def _parse_object_type(
154
- cls: type[Any],
155
- text: str,
156
- /,
157
- *,
158
- case_sensitive: bool = False,
159
- extra: ParseObjectExtra | None = None,
154
+ cls: type[Any], text: str, /, *, case_sensitive: bool = False
160
155
  ) -> Any:
161
156
  """Parse text."""
162
157
  if issubclass(cls, NoneType):
@@ -226,17 +221,6 @@ def _parse_object_type(
226
221
  return parse_timedelta(text)
227
222
  except ParseTimedeltaError:
228
223
  raise _ParseObjectParseError(type_=cls, text=text) from None
229
- if extra is not None:
230
- try:
231
- parser = one(p for c, p in extra.items() if issubclass(cls, c))
232
- except OneEmptyError:
233
- pass
234
- except OneNonUniqueError as error:
235
- raise _ParseObjectExtraNonUniqueError(
236
- type_=cls, text=text, first=error.first, second=error.second
237
- ) from None
238
- else:
239
- return parser(text)
240
224
  raise _ParseObjectParseError(type_=cls, text=text)
241
225
 
242
226
 
@@ -296,6 +280,21 @@ def _parse_object_dict_type(
296
280
  raise _ParseObjectParseError(type_=type_, text=text) from None
297
281
 
298
282
 
283
+ def _parse_object_extra(cls: Any, text: str, extra: ParseObjectExtra, /) -> Any:
284
+ try:
285
+ parser = one(
286
+ p for c, p in extra.items() if (cls is c) or is_subclass_gen(cls, c)
287
+ )
288
+ except OneEmptyError:
289
+ raise _ParseObjectParseError(type_=cls, text=text) from None
290
+ except OneNonUniqueError as error:
291
+ raise _ParseObjectExtraNonUniqueError(
292
+ type_=cls, text=text, first=error.first, second=error.second
293
+ ) from None
294
+ else:
295
+ return parser(text)
296
+
297
+
299
298
  def _parse_object_list_type(
300
299
  type_: Any,
301
300
  text: str,
@@ -368,9 +367,7 @@ def _parse_object_set_type(
368
367
  raise _ParseObjectParseError(type_=type_, text=text) from None
369
368
 
370
369
 
371
- def _parse_object_union_type(
372
- type_: Any, text: str, /, *, extra: ParseObjectExtra | None = None
373
- ) -> Any:
370
+ def _parse_object_union_type(type_: Any, text: str, /) -> Any:
374
371
  if type_ is Number:
375
372
  try:
376
373
  return parse_number(text)
@@ -383,13 +380,6 @@ def _parse_object_union_type(
383
380
  return parse_duration(text)
384
381
  except ParseDurationError:
385
382
  raise _ParseObjectParseError(type_=type_, text=text) from None
386
- if extra is not None:
387
- try:
388
- parser = one(p for c, p in extra.items() if c is type_)
389
- except OneEmptyError:
390
- pass
391
- else:
392
- return parser(text)
393
383
  raise _ParseObjectParseError(type_=type_, text=text) from None
394
384
 
395
385
 
@@ -466,6 +456,9 @@ def serialize_object(
466
456
  extra: SerializeObjectExtra | None = None,
467
457
  ) -> str:
468
458
  """Convert an object to text."""
459
+ if extra is not None:
460
+ with suppress(_SerializeObjectSerializeError):
461
+ return _serialize_object_extra(obj, extra)
469
462
  if (obj is None) or isinstance(
470
463
  obj, bool | int | float | str | Path | Sentinel | Version
471
464
  ):
@@ -504,8 +497,6 @@ def serialize_object(
504
497
  return _serialize_object_set(
505
498
  obj, list_separator=list_separator, pair_separator=pair_separator
506
499
  )
507
- if extra is not None:
508
- return _serialize_object_extra(obj, extra)
509
500
  raise _SerializeObjectSerializeError(obj=obj)
510
501
 
511
502
 
@@ -537,10 +528,7 @@ def _serialize_object_dict(
537
528
  def _serialize_object_extra(obj: Any, extra: SerializeObjectExtra, /) -> str:
538
529
  try:
539
530
  serializer = one(
540
- s
541
- for c, s in extra.items()
542
- if (isinstance(c, type) and isinstance(obj, c))
543
- or isinstance(obj, get_args(c))
531
+ s for c, s in extra.items() if (obj is c) or is_instance_gen(obj, c)
544
532
  )
545
533
  except OneEmptyError:
546
534
  raise _SerializeObjectSerializeError(obj=obj) from None