-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[python-nextgen] optionally support float strict type #14618
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
Conversation
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
@@ -443,12 +449,20 @@ private String getPydanticType(CodegenParameter cp, | |||
fieldCustomization.add("multiple_of=" + cp.getMultipleOf()); | |||
} | |||
|
|||
if (floatStrictType) { |
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.
This code path is used for json schema number (float + int) and float only processing. Number should allow both in.
How about:
- not adding the strict info when it is number with no format
- adding it when it is float only
- adding tests of both of those cases (number vs float only) with and without strict on
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.
It's an option so users can choose whether they want float in strict type or not.
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.
Right but that option should only apply to floats right? The way it is now looks like you are applying float strict when the spec has type: number
which should allow in float and int. Did I misunderstand something?
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.
- number: confloat(strict=True, le=543.2, ge=32.1) = ...
- float: Optional[confloat(strict=True, le=987.6, ge=54.3)] = None
- double: Optional[confloat(strict=True, le=123.4, ge=67.8)] = None
+ number: confloat(le=543.2, ge=32.1) = ...
+ float: Optional[confloat(le=987.6, ge=54.3)] = None
+ double: Optional[confloat(le=123.4, ge=67.8)] = None
As illustrated in the sample diff as part of this change, the option (when set to false) simply removes strict=True
.
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.
Why are you applying strict float to type number with no format? Won't it throw a validation error if an integer input is given to it? Integer input is valid for that definition per
https://json-schema.org/understanding-json-schema/reference/numeric.html#number
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.
Why are you applying strict float to type number with no format?
It's a user decision - they can switch on or off strict mode via an option.
You can find more about why some users prefer strict mode in https://docs.pydantic.dev/blog/pydantic-v2/#strict-mode.
Thanks a lot for doing this :) |
To close #14499
PR checklist
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*
.For Windows users, please run the script in Git BASH.
master
(6.3.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks)FYI @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @arun-nalla (2019/11) @spacether (2019/11) @krjakbrjak (2023/02)