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?
to your account
import sys; print(sys.version)
import pydantic; print(pydantic.VERSION)
When creating a pydantic dataclass that has a FrozenSet member, initialization fails in the @dataclass decorator.
from typing import FrozenSet
from pydantic.dataclasses import dataclass
will fail with an assertion error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "pydantic/dataclasses.py", line 125, in pydantic.dataclasses.dataclass.wrap
File "pydantic/dataclasses.py", line 87, in pydantic.dataclasses._process_class
File "pydantic/main.py", line 710, in pydantic.main.create_model
File "pydantic/main.py", line 228, in pydantic.main.MetaModel.__new__
File "pydantic/fields.py", line 145, in pydantic.fields.Field.infer
File "pydantic/fields.py", line 122, in pydantic.fields.Field.__init__
File "pydantic/fields.py", line 187, in pydantic.fields.Field.prepare
File "pydantic/fields.py", line 252, in pydantic.fields.Field._populate_sub_fields
Looking in the pydantic source code, it looks like this has to do with how it determines the type of the field. Specifically, the issue is that FrozenSet, somewhat counter-intuitively, does not appear to be a subtype of Set:
>>> from typing import FrozenSet, Set
>>> issubclass(FrozenSet, Set)
It looks like this if-else block has to be amended with a specific case for FrozenSet.
The text was updated successfully, but these errors were encountered:
This is not a bug, but a feature request to support the typing type FrozenSet which I'd be happy to do. It should accept or convert iterables to frozenset not set.
We should also improve the error handling to explain what's going on.
FrozenSet won't be a subtype of set since it's a typing object and as an object doesn't behave anything like a set. Same as List isn't a subtype of list.
PR welcome, but probably won't be merged until v1.1.
Sorry, something went wrong.
Better error for unsuported "typing" objects.
Add a better error message for fields with types from the typing
module that are not directly supported by Pydantic. Previously,
it caused a cryptic assertion failure.
Add support for frozenset fields.
Provide example of FrozenSet usage.
Add documentation of changes.
Address review comments.
Also provide an example of their usage.
No branches or pull requests