-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
python-pydantic-v1: Keep trailing commas for enum validation tuples #19985
python-pydantic-v1: Keep trailing commas for enum validation tuples #19985
Conversation
thanks for the PR can you please add a test schema (enum with a single item) in |
Tagging @multani for early feedback. Will work on adding small tests |
Updated samples and added a test |
a1a1537
to
d679874
Compare
Tagging other members of Python committee |
@chiragjn did you consider replacing the tuples by lists instead? Semantically, I think it would be more "correct", and syntax-wise it would also prevent this kind of problem. |
Hmm, sure I don't mind doing that |
I'm not sure if that makes such a difference ; if this was a performance problem too, they should be created only once anyway as they are all constants in the end. We can merge this as it is though. |
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.
lgtm
@wing328 any preference between tuples and lists? Lists would have prevented this bug in the first place, at the expense of a slight performance penalty.
to me, this is more like an edge case so my take is to use tuple instead. |
It can happen that sometimes a enum just has a single member
This can result in a pydantic validator that can be incorrect
E.g.
If I do some substring of "test", e.g.
TestClass(type="tes")
this validation will not failThen trailing
,
in this case is requiredPR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)