dataclass-extensions 0.2.0__tar.gz → 0.2.2__tar.gz

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.
Files changed (19) hide show
  1. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/PKG-INFO +1 -1
  2. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/pyproject.toml +1 -5
  3. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/src/dataclass_extensions/decode.py +16 -1
  4. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/src/dataclass_extensions/registrable.py +5 -0
  5. dataclass_extensions-0.2.2/src/dataclass_extensions/version.py +1 -0
  6. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/src/dataclass_extensions.egg-info/PKG-INFO +1 -1
  7. dataclass_extensions-0.2.0/src/dataclass_extensions/version.py +0 -1
  8. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/LICENSE +0 -0
  9. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/README.md +0 -0
  10. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/setup.cfg +0 -0
  11. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/src/dataclass_extensions/__init__.py +0 -0
  12. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/src/dataclass_extensions/encode.py +0 -0
  13. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/src/dataclass_extensions/py.typed +0 -0
  14. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/src/dataclass_extensions/types.py +0 -0
  15. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/src/dataclass_extensions/utils.py +0 -0
  16. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/src/dataclass_extensions.egg-info/SOURCES.txt +0 -0
  17. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/src/dataclass_extensions.egg-info/dependency_links.txt +0 -0
  18. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/src/dataclass_extensions.egg-info/requires.txt +0 -0
  19. {dataclass_extensions-0.2.0 → dataclass_extensions-0.2.2}/src/dataclass_extensions.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dataclass-extensions
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Additional functionality for Python dataclasses
5
5
  Author-email: Pete Walsh <epwalsh10@gmail.com>
6
6
  License: Apache License
@@ -91,13 +91,9 @@ exclude = [
91
91
  ".tox",
92
92
  "__pypackages__",
93
93
  "_build",
94
- "buck-out",
95
94
  "build",
96
95
  "dist",
97
- "node_modules",
98
- "doc",
99
- "pretrain_data",
100
- "inference",
96
+ "src/test/_type_alias.py",
101
97
  ]
102
98
 
103
99
  [tool.ruff.lint.per-file-ignores]
@@ -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
- type_hints = typing.get_type_hints(allowed_type)
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:
@@ -0,0 +1 @@
1
+ VERSION = "0.2.2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dataclass-extensions
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Additional functionality for Python dataclasses
5
5
  Author-email: Pete Walsh <epwalsh10@gmail.com>
6
6
  License: Apache License
@@ -1 +0,0 @@
1
- VERSION = "0.2.0"