Skip to content
New issue

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

constrained set type "conset" #1623

Closed
patrickkwang opened this issue Jun 10, 2020 · 2 comments
Closed

constrained set type "conset" #1623

patrickkwang opened this issue Jun 10, 2020 · 2 comments
Labels
feature request help wanted Pull Request welcome

Comments

@patrickkwang
Copy link

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
@samuelcolvin
Copy link
Member

👍 PR welcome.

@samuelcolvin samuelcolvin added the help wanted Pull Request welcome label Jun 11, 2020
@patrickkwang patrickkwang mentioned this issue Jun 11, 2020
4 tasks
@samuelcolvin
Copy link
Member

fixed by #1627

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request help wanted Pull Request welcome
Projects
None yet
Development

No branches or pull requests

2 participants