We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
None
Union
packages marshmallow==3.6.1 marshmallow-dataclass==7.6.0 marshmallow-enum==1.5.1 marshmallow-union==0.1.15
from typing import List, Union from marshmallow_dataclass import dataclass import dataclasses noned = lambda: dataclasses.field( metadata=dict( required=False, missing=None, default=None, ) ) @dataclass class Inner: inner_var: int @dataclass class Test: req: int = None var: Union[int, Inner, List[Inner]] = noned()
I get the following error trying to use the class
/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/dataclasses.py:1019: in dataclass return wrap(cls) /usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/dataclasses.py:1011: in wrap return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen) /usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/dataclasses.py:925: in _process_class _init_fn(flds, /usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/dataclasses.py:502: in _init_fn raise TypeError(f'non-default argument {f.name!r} ' E TypeError: non-default argument 'var' follows default argument
It seems like default and missing None are not being assigned properly?
The text was updated successfully, but these errors were encountered:
Your type annotation is incorrect. A field of typeUnion[int, Inner, List[Inner]] cannot be None.
Union[int, Inner, List[Inner]]
Sorry, something went wrong.
oh how come? the following is valid. am i missing something?
@dataclass class Inner: inner_var: int = None
None is not an instance of int. You can use Optional[int] or Union[int, None]
Optional[int]
Union[int, None]
See typing — Support for type hints — Python 3.8.3 documentation https://docs.python.org/3/library/typing.html#typing.Optional
No branches or pull requests
packages
marshmallow==3.6.1
marshmallow-dataclass==7.6.0
marshmallow-enum==1.5.1
marshmallow-union==0.1.15
I get the following error trying to use the class
It seems like default and missing
None
are not being assigned properly?The text was updated successfully, but these errors were encountered: