-
-
Notifications
You must be signed in to change notification settings - Fork 590
Jsonschema accepts np.NaNs as numeric, can I change that behaviour somehow? #357
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
Comments
Pass in a more restrictive type to the The default is |
The thing about this is that it's not exactly easy to exclude I realize that you can do something like Any thoughts on adapting the code to reject |
I think you're making it sound more obvious than it is that NaN isn't a number, both answers seem reasonable to me, so I'm inclined to leave things as-is unless there's really strong reasoning. You'll note obviously that Python itself considers NaN a number, and since NaN isn't a JSON thing, we're again in spec-less territory. That implementation flip flopped it looks like, and at least in scanning that issue quickly, I don't see the change as being intentional from there alone, so not sure how much weight that issue alone gives. It's quite easy to change the behavior as you've already found it looks like though. |
Pondering this...I think it is indeed obvious to me that NaN is, well, a "number" in some sense. But even if it is a number, it's not a valid number, which is why (I would think) that jsonschema would want to reject it when given it in a field that expects a number. (The ultimate conclusion over at the linked repo does seem to have been not to accept NaN: https://github.com/tdegrunt/jsonschema/blob/master/lib/validator.js#L293 is the line that rejects all of NaN, Infinity, and -Infinity, and https://github.com/tdegrunt/jsonschema/blob/master/test/attributes.js#L24 is the test that explicitly shows that validating Now, all of that said, while I've convinced myself that this is the right approach, I realize that you may not be convinced. :-) And of course, in the meantime, I still need to exclude |
Think of it in the current form as "number" is interpreted by FWIW you can do stupid type trickery to create a type that responds true for everything but NaN, but the ability to redefine these kinds of things is exactly what motivated the type checker interface changes, so possibly you just want to upgrade :) |
This issue came up again in #1222, although I didn't really emphasize the right aspect there. I'd like to argue again, as Tahnan argues above, that |
Given that:
my position hasn't changed here I'm afraid. |
No description provided.
The text was updated successfully, but these errors were encountered: