Skip to content

[python-nextgen] optionally support float strict type#14618

Merged
wing328 merged 2 commits intomasterfrom
python-nextgen-float
Feb 12, 2023
Merged

[python-nextgen] optionally support float strict type#14618
wing328 merged 2 commits intomasterfrom
python-nextgen-float

Conversation

@wing328
Copy link
Copy Markdown
Member

@wing328 wing328 commented Feb 4, 2023

  • optionally support float strict type via the option "floatStrictType" (default to true)
  • add a test

To close #14499

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    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*.
    For Windows users, please run the script in Git BASH.
  • In case you are adding a new generator, run the following additional script :
    ./bin/utils/ensure-up-to-date.sh
    
    Commit all changed files.
  • File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

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)

Comment thread bin/configs/python-nextgen-aiohttp.yaml
Copy link
Copy Markdown
Member

@tomplus tomplus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread bin/configs/python-nextgen-aiohttp.yaml
fieldCustomization.add("multiple_of=" + cp.getMultipleOf());
}

if (floatStrictType) {
Copy link
Copy Markdown
Contributor

@spacether spacether Feb 4, 2023

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

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Contributor

@spacether spacether Feb 7, 2023

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?

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Contributor

@spacether spacether Feb 8, 2023

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

Copy link
Copy Markdown
Member Author

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.

@wing328 wing328 merged commit 72c02e4 into master Feb 12, 2023
@wing328 wing328 deleted the python-nextgen-float branch February 12, 2023 11:44
@aimxhaisse
Copy link
Copy Markdown

Thanks a lot for doing this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REQ][python-nextgen] make float parsing more lenient

4 participants