dataclass-extensions 0.2.0__py3-none-any.whl → 0.2.2__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.
- dataclass_extensions/decode.py +16 -1
- dataclass_extensions/registrable.py +5 -0
- dataclass_extensions/version.py +1 -1
- {dataclass_extensions-0.2.0.dist-info → dataclass_extensions-0.2.2.dist-info}/METADATA +1 -1
- dataclass_extensions-0.2.2.dist-info/RECORD +13 -0
- dataclass_extensions-0.2.0.dist-info/RECORD +0 -13
- {dataclass_extensions-0.2.0.dist-info → dataclass_extensions-0.2.2.dist-info}/WHEEL +0 -0
- {dataclass_extensions-0.2.0.dist-info → dataclass_extensions-0.2.2.dist-info}/licenses/LICENSE +0 -0
- {dataclass_extensions-0.2.0.dist-info → dataclass_extensions-0.2.2.dist-info}/top_level.txt +0 -0
dataclass_extensions/decode.py
CHANGED
|
@@ -8,6 +8,7 @@ from datetime import datetime
|
|
|
8
8
|
from enum import Enum
|
|
9
9
|
from typing import Any, Callable, ClassVar, Type, TypeVar
|
|
10
10
|
|
|
11
|
+
from .registrable import Registrable
|
|
11
12
|
from .types import *
|
|
12
13
|
|
|
13
14
|
C = TypeVar("C", bound=Dataclass)
|
|
@@ -95,6 +96,9 @@ def _coerce(
|
|
|
95
96
|
except TypeError:
|
|
96
97
|
pass
|
|
97
98
|
|
|
99
|
+
if allowed_type is float and _safe_isinstance(value, (float, int)):
|
|
100
|
+
return float(value)
|
|
101
|
+
|
|
98
102
|
origin = getattr(allowed_type, "__origin__", None)
|
|
99
103
|
args = getattr(allowed_type, "__args__", None)
|
|
100
104
|
if (origin is list or origin is collections.abc.MutableSequence) and _safe_isinstance(
|
|
@@ -163,7 +167,18 @@ def _coerce(
|
|
|
163
167
|
# e.g. TypedDict
|
|
164
168
|
or _safe_issubclass(allowed_type, dict)
|
|
165
169
|
) and _safe_isinstance(value, dict):
|
|
166
|
-
|
|
170
|
+
if _safe_issubclass(allowed_type, Registrable):
|
|
171
|
+
type_name = value.get("type", allowed_type._default_type)
|
|
172
|
+
if type_name is not None:
|
|
173
|
+
allowed_type = allowed_type.get_registered_class(type_name)
|
|
174
|
+
|
|
175
|
+
try:
|
|
176
|
+
type_hints = typing.get_type_hints(allowed_type)
|
|
177
|
+
except NameError as e:
|
|
178
|
+
raise NameError(
|
|
179
|
+
f"{str(e)}. If you're using 'from __future__ import annotations' you may need to import this type."
|
|
180
|
+
) from e
|
|
181
|
+
|
|
167
182
|
kwargs = {}
|
|
168
183
|
for k, v in value.items():
|
|
169
184
|
try:
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import dataclasses
|
|
4
|
+
import sys
|
|
4
5
|
import typing
|
|
5
6
|
from dataclasses import dataclass
|
|
6
7
|
from typing import Callable, ClassVar, Type, TypeVar
|
|
7
8
|
|
|
8
9
|
R = TypeVar("R", bound="Registrable")
|
|
9
10
|
|
|
11
|
+
if sys.version_info < (3, 11):
|
|
12
|
+
# HACK: work-around for https://stackoverflow.com/q/70400639/4151392
|
|
13
|
+
dataclasses.InitVar.__call__ = lambda *_: None # type: ignore
|
|
14
|
+
|
|
10
15
|
|
|
11
16
|
@dataclass
|
|
12
17
|
class Registrable:
|
dataclass_extensions/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = "0.2.
|
|
1
|
+
VERSION = "0.2.2"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
dataclass_extensions/__init__.py,sha256=jpgRh5jjj9jM1tkhTVvB-aDThI2v4tAlq_WpR0-NOSI,255
|
|
2
|
+
dataclass_extensions/decode.py,sha256=3lMxjlw-JJ6-M0Hi-P-yVF9TRyfO5C3wAgidafKpz1w,6967
|
|
3
|
+
dataclass_extensions/encode.py,sha256=rctJHAwlSnjOw0rTGbHRWigb2BT4DI3FYGiDzAjDmEQ,3233
|
|
4
|
+
dataclass_extensions/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
dataclass_extensions/registrable.py,sha256=TWdJ0vLkOTsw5Zm8uOk7Ueh6ZODn-q_2jht1uWRkpzE,4608
|
|
6
|
+
dataclass_extensions/types.py,sha256=UwSV0MKjFDaK4dlgm72vJHHr6-8QNe8jMhbTZGOMIJM,247
|
|
7
|
+
dataclass_extensions/utils.py,sha256=8cigzY9JDEWexWXlcMxXyf27S50-1ZPMNmn4zUSrc6k,935
|
|
8
|
+
dataclass_extensions/version.py,sha256=qleN2zQctO8stGYcfqFUyavqMP9pxdKBbwgZWyKxPWQ,18
|
|
9
|
+
dataclass_extensions-0.2.2.dist-info/licenses/LICENSE,sha256=YvuKOpYh3COIF0yqq-nCMXtpS7mh1GyYvPVlW2j1G-M,11359
|
|
10
|
+
dataclass_extensions-0.2.2.dist-info/METADATA,sha256=L-BPjeYE7Z-jFhCVq9OIJ0HJLW0pNFU52NhyjtFe48w,15215
|
|
11
|
+
dataclass_extensions-0.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
dataclass_extensions-0.2.2.dist-info/top_level.txt,sha256=njfdeqLtTThNGwqnoKu4JV8J1287xGAeEwyESpoU-k8,21
|
|
13
|
+
dataclass_extensions-0.2.2.dist-info/RECORD,,
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
dataclass_extensions/__init__.py,sha256=jpgRh5jjj9jM1tkhTVvB-aDThI2v4tAlq_WpR0-NOSI,255
|
|
2
|
-
dataclass_extensions/decode.py,sha256=dstNb-RU8i3jGoTlo165UlSbyG3MhAgbc-O54mdlxqo,6329
|
|
3
|
-
dataclass_extensions/encode.py,sha256=rctJHAwlSnjOw0rTGbHRWigb2BT4DI3FYGiDzAjDmEQ,3233
|
|
4
|
-
dataclass_extensions/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
dataclass_extensions/registrable.py,sha256=6lpMHnOypZ_CPgTwiYglt0egpmhsFaOUmKC-LOBoR_Y,4425
|
|
6
|
-
dataclass_extensions/types.py,sha256=UwSV0MKjFDaK4dlgm72vJHHr6-8QNe8jMhbTZGOMIJM,247
|
|
7
|
-
dataclass_extensions/utils.py,sha256=8cigzY9JDEWexWXlcMxXyf27S50-1ZPMNmn4zUSrc6k,935
|
|
8
|
-
dataclass_extensions/version.py,sha256=w9Iw7QVvd8lme2wKwEbCo5IgetVjSfFBOOYAcA_Q0Ns,18
|
|
9
|
-
dataclass_extensions-0.2.0.dist-info/licenses/LICENSE,sha256=YvuKOpYh3COIF0yqq-nCMXtpS7mh1GyYvPVlW2j1G-M,11359
|
|
10
|
-
dataclass_extensions-0.2.0.dist-info/METADATA,sha256=QXmnDLRIZD1WwOtOGOVFBv0uj1AXxDcHu6McG_-pvz4,15215
|
|
11
|
-
dataclass_extensions-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
-
dataclass_extensions-0.2.0.dist-info/top_level.txt,sha256=njfdeqLtTThNGwqnoKu4JV8J1287xGAeEwyESpoU-k8,21
|
|
13
|
-
dataclass_extensions-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
{dataclass_extensions-0.2.0.dist-info → dataclass_extensions-0.2.2.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|