Skip to content

Commit dc6dbb9

Browse files
committed
recursive definitions fix
1 parent 81d5a36 commit dc6dbb9

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

nvelope/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "0.3.0"
1+
__version__ = "0.3.1"
22

33
from nvelope.nvelope import *

nvelope/nvelope.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ def asdict(obj):
2424
return {f.name: getattr(obj, f.name) for f in fields(obj)}
2525

2626

27+
def maybe_missing_field(f) -> bool:
28+
if isinstance(f.type, str):
29+
return f.type.startswith("MaybeMissing[")
30+
return (
31+
hasattr(f.type, "__origin__")
32+
and inspect.isclass(f.type.__origin__)
33+
and issubclass(f.type.__origin__, MaybeMissing)
34+
)
35+
36+
2737
class MaybeMissing(Generic[T], ABC):
2838
@abstractmethod
2939
def value(self) -> T:
@@ -108,11 +118,7 @@ def from_json(cls, parsed: JSON) -> "Obj":
108118
kwargs = {}
109119
for f in fields(cls):
110120
conv: Conversion = cls._conversion[f.name]
111-
if (
112-
hasattr(f.type, "__origin__")
113-
and inspect.isclass(f.type.__origin__)
114-
and issubclass(f.type.__origin__, MaybeMissing)
115-
):
121+
if maybe_missing_field(f):
116122
kwargs[f.name] = (
117123
Jst(conv.from_json(parsed[f.name])) if f.name in parsed else Miss()
118124
)
@@ -174,11 +180,7 @@ def from_json(cls, parsed: JSON) -> "Obj":
174180
for field in fields(cls):
175181
conv: Conversion = cls._conversion[field.name]
176182
maybe_unescaped_name = cls._maybe_renamed(field.name)
177-
if (
178-
hasattr(field.type, "__origin__")
179-
and inspect.isclass(field.type.__origin__)
180-
and issubclass(field.type.__origin__, MaybeMissing)
181-
):
183+
if maybe_missing_field(field):
182184
kwargs[field.name] = (
183185
Jst(conv.from_json(parsed[maybe_unescaped_name]))
184186
if maybe_unescaped_name in parsed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "nvelope"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
description = "Painless JSON marshalling and unmarshalling"
55
authors = ["monomonedula <valh@tuta.io>"]
66
readme = 'README.md'

0 commit comments

Comments
 (0)