-
Notifications
You must be signed in to change notification settings - Fork 307
introduce iterable
schema
#1792
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
base: main
Are you sure you want to change the base?
Conversation
CodSpeed Performance ReportMerging #1792 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Python, an iterable is an object that has an __iter__()
method and presumably can produce iterators multiple times from it. What if users want the iterable to just be validated that we can grab an iterator from it (that is what input.validate_iter()
is doing), and leave it as is? I guess the issue is that we can't validate the type of the values this way?
Or maybe my point is that as it stands now, we support ABCs to try to preserve the input type to our best knowledge. If someone uses With |
I guess exactly this, yes. Validation may in general lead to coercions (e.g. string '1' to integer 1) so
A great question. Perhaps you're right, and the answer is that For So... seems like this needs more design? |
It feels to me that several users reported issues with
|
Change Summary
Adds
iterable_schema
, which is intended to solve my proposal in pydantic/pydantic#9541 (comment)pydantic
should update all existing uses ofgenerator_schema
toiterable_schema
, which allows forlazy = False
as a field-level setting. We should probably also have a config setting calledlazy_iterables
or similar, (TODO).If we want to allow support for
Iterator
andGenerator
types inpydantic
, those can usegenerator_schema
.Related issue number
pydantic/pydantic#9541
Checklist
pydantic-core
(except for expected changes)