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

ConstrainedFloat schema: differences between IEEE floats and json #1422

Merged
merged 9 commits into from Apr 30, 2020

Conversation

vdwees
Copy link
Contributor

@vdwees vdwees commented Apr 23, 2020

Change Summary

Modify constraints on ConstrainedFloat schema to account for differences between IEEE floats and json

Transformations applied:

  • remove field exclusiveMinimum if it is equal to -math.inf
  • remove field minimum if it is equal to -math.inf
  • remove field exclusiveMaximum if it is equal to math.inf
  • remove field maximum if it is equal to math.inf

Related issue number

#1417

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)

@codecov
Copy link

codecov bot commented Apr 23, 2020

Codecov Report

Merging #1422 into master will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #1422   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         3741      3759   +18     
  Branches       740       747    +7     
=========================================
+ Hits          3741      3759   +18     
Impacted Files Coverage Δ
pydantic/schema.py 100.00% <100.00%> (ø)
pydantic/types.py 100.00% <100.00%> (ø)
pydantic/utils.py 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3cd8b1e...78d1218. Read the comment docs.

changes/1417-vdwees.md Outdated Show resolved Hide resolved
changes/1417-vdwees.md Outdated Show resolved Hide resolved
pydantic/types.py Outdated Show resolved Hide resolved
pydantic/types.py Outdated Show resolved Hide resolved
pydantic/schema.py Outdated Show resolved Hide resolved
@samuelcolvin
Copy link
Member

good point from @chris-allnutt, we should use the JSON values Infinity and -Infinity.

@vdwees
Copy link
Contributor Author

vdwees commented Apr 24, 2020

good point from @chris-allnutt, we should use the JSON values Infinity and -Infinity.

Its tricky because NaN, Infinity, and -Infinity are not valid JSON, but a lot of python json libs include them.

vdwees and others added 3 commits April 24, 2020 16:25
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
@samuelcolvin
Copy link
Member

The acid test for me (both semantically and practically) is: what happens in js with JSON.parse(...)? I'd suggest we follow that.

(I'm on my phone atm., so don't actually know the answer)

Difference of styles :)

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
@vdwees
Copy link
Contributor Author

vdwees commented Apr 24, 2020

Here is the javascript JSON behaviour (tested in Firefox, but this is a pretty fundamental language feature):

>>JSON.stringify({var:Infinity})
"{\"var\":null}"
>>JSON.parse("{\"var\":Infinity}")
SyntaxError: JSON.parse: unexpected character at line 1 column 8 of the JSON data

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

otherwise LGTM.

pydantic/schema.py Outdated Show resolved Hide resolved
@samuelcolvin samuelcolvin merged commit 833d33d into pydantic:master Apr 30, 2020
@samuelcolvin
Copy link
Member

thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants