-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Feature Request
Is there a way to benefit from the best of both worlds: [uniqueness] from set and length constraints from conlist()? - @neimad1985 in #1472 (comment)
Also important to me is that sets are unordered.
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.5.1
pydantic compiled: True
install path: .../venv/lib/python3.8/site-packages/pydantic
python version: 3.8.1 (default, Feb 19 2020, 09:57:06) [Clang 11.0.0 (clang-1100.0.33.17)]
platform: macOS-10.15.5-x86_64-i386-64bit
optional deps. installed: []
Example behavior:
from pydantic import conset
class ConSetModel(BaseModel):
v: conset(int, max_items=3)
print(ConSetModel(v=[1, 2, 2]).v) # {1, 2}
print(ConSetModel(v=[1, 2, 2, 3]).v) # {1, 2, 3}
print(ConSetModel(v=[1, 2, 3, 4]).v) # raises ValidationError