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
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "pydantic/main.py", line 252, in pydantic.main.ModelMetaclass.__new__
File "pydantic/fields.py", line 308, in pydantic.fields.ModelField.infer
File "pydantic/schema.py", line 864, in pydantic.schema.get_annotation_from_field_info
ValueError: On field "my_frozen_set" the following field constraints are set but not enforced: min_items.
For more details see https://pydantic-docs.helpmanual.io/usage/schema/#unenforced-field-constraints
Since FrozenSet is simply the immutable version of Set, it should be possible to use min_items to validate the size of the set.
Edit:
The reason I expected FrozenSet to work the same way as mutable Set is because the docs describe them in the exact same manner. Even though frozen sets are not mentioned in the constrained types section, it's a little natural to (wrongly) assume parallel functionalities are available for it.
The text was updated successfully, but these errors were encountered:
Hello @snazzyfox
Unfortunately we currently have some custom logic, which doesn't support Frozenset as the origin is frozenset.
We could probably just add a if issubclass(origin, frozenset) ... and add the immutability in conset or duplicate some logic to have a confrozenset
Thanks for taking a look! This totally makes sense.
I think whether we create confrozenset or conset(frozen=True) depends on if we want to also duplicate the ConstrainedSet class. The code for frozen sets will most probably be almost identical, just with a different base class. If there's a way we can update/reuse the existing class, adding a immutable option to conset would make more sense.
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:Code Example
This works fine:
Using
FrozenSet
instead ofSet
doesn't work:This causes an error at definition time:
Since
FrozenSet
is simply the immutable version ofSet
, it should be possible to usemin_items
to validate the size of the set.Edit:
The reason I expected
FrozenSet
to work the same way as mutableSet
is because the docs describe them in the exact same manner. Even though frozen sets are not mentioned in the constrained types section, it's a little natural to (wrongly) assume parallel functionalities are available for it.The text was updated successfully, but these errors were encountered: