You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running the example code from the NewType docstring, I get the following exception:
import marshmallow.validate
IPv4 = NewType('IPv4', str, validate=marshmallow.validate.Regexp(r'^([0-9]{1,3}\\.){3}[0-9]{1,3}$'))
@dataclass
class MyIps:
ips: List[IPv4]
MyIps.Schema().load({"ips": ["0.0.0.0", "grumble grumble"]})
TypeError: IPv4 is not a dataclass and cannot be turned into one.
The issue seems to happen in typing_inspect.py at line 287, in function is_new_type. For versions prior to Python 3.10.0, the check is the following:
return (tp is NewType or
(getattr(tp, '__supertype__', None) is not None and
getattr(tp, '__qualname__', '') == 'NewType.<locals>.new_type' and
tp.__module__ in ('typing', 'typing_extensions')))
However, in the case of new types created via marshmallow_dataclass, the __module__ is set to 'marshmallow_dataclass'. Therefore, the new type is not recognized as such and marshmallow_dataclass treats it as a nested field.
I'm using Python 3.8 and marshmallow-dataclass==8.5.8
The text was updated successfully, but these errors were encountered:
When running the example code from the NewType docstring, I get the following exception:
The issue seems to happen in typing_inspect.py at line 287, in function is_new_type. For versions prior to Python 3.10.0, the check is the following:
However, in the case of new types created via marshmallow_dataclass, the __module__ is set to 'marshmallow_dataclass'. Therefore, the new type is not recognized as such and marshmallow_dataclass treats it as a nested field.
I'm using Python 3.8 and marshmallow-dataclass==8.5.8
The text was updated successfully, but these errors were encountered: