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
0
should not be considered equal to False
#575
Comments
The latter likely related to your still-open #529. I actually... don't have an opinion yet :D, have to think about what I expect. Obviously the inconsistency is wrong, but not sure which to expect. I guess slightly leaning towards them always being equal, but have to think. Thoughts welcome of course :), and yeah thanks for filing obviously! |
It's not obvious, thats for sure! My preference would be to treat all numeric zeros (integer or float) as equal, but booleans as unequal to numbers. Either way, it's a question that should be addressed by the specification since it does change the semantics. Treating booleans as unequal to numbers unlocks several nice optimisations in the logic I usr for canonicalising schemas and calculating intersections - with I can treat them as enums; without I have to keep and track the type information too. Not sure if that will convince anyone but me though 😅 Final fun fact: IEEE754 allows you to represent negative zero, but it can't be serialised as JSON. So hypothesis-jsonschema already has special handling for zeros, even before this issue! |
Having JSON Schema as a spec has historically (and will remain) language-agnostic, so I disagree with this being in the spec. It would require that languages that distinguish between integers and booleans (e.g. C# and other .Net languages) would have to support something that is contrary to the language/framework in which their written, which would be a poor developer experience. If an implementation that is written in a language that supports equivalency between integers and booleans wishes to support this, then I see it as an augmentation over JSON Schema and should be documented as such. |
The options are that either:
The former is certainly unintuitive, but the latter is a disaster for interoperability: imagine the developer experience of an instance passing validation on the (JS) frontend, but failing at the (C#) backend with the same schema! |
For what it's worth, the latter is *already* the case :) -- e.g., take a
language with no ability whatsoever to represent false, which instead just
deserializes falses to 0. E.g. a C89 implementation presumably. There are
other examples (in the spec and otherwise, of languages that don't have
separate integer and float types, say).
But the spec already acknowledges such a thing:
JSON Schema is programming language agnostic, and supports the full range
of values described in the data model. Be aware, however, that some
languages and JSON parsers may not be able to represent in memory the full
range of values describable by JSON.
…On Mon, Jul 1, 2019 at 8:43 PM Zac Hatfield-Dodds ***@***.***> wrote:
JSON Schema *as a spec* has historically (and will remain)
language-agnostic, so I disagree with this being in the spec. It would
require that languages that *distinguish* between integers and booleans
(e.g. C# and other .Net languages) would have to support something that is
contrary to the language/framework in which their written, which would be a
poor developer experience.
The options are that either:
- Jsonschema has different equality semantics to (some) host
languages, or
- There are instances which *may or may not validate* against a given
schema depending on which language you're using.
The former is certainly unintuitive, but the latter is a disaster for
interoperability: imagine the developer experience of an instance passing
validation on the (JS) frontend, but failing at the (C#) backend with the
same schema!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#575>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACQQXTVACLRNVC42OTXML3P5KQDVANCNFSM4H4OGS4Q>
.
|
My problem here is that "different languages, even among those that distinguish booleans from integers, have different validation semantics" is the opposite of a language-agnostic specification. To put that another way, a language-agnostic spec would have the same semantics regardless of language, so that whether an instance validates against some schema is always independent of which language is being used to validate it. I think this is a very important property for a validation spec to have. |
Uh another funny example of this by the way, or at least a slightly related one -- |
A-ha! Looking in the core specificiation (instead of the validation spec):
So |
to evade failures due to overridden equals e.g. pandas. Patches changes of python-jsonschema#575.
…)... to evade failures due to overridden equals e.g. pandas. Patches changes of python-jsonschema#575.
69acf529 Merge pull request #572 from json-schema-org/default-reviewers 26a51ca3 Merge pull request #575 from jdesrosiers/add-package-json d0e80a96 Re-add package.json 88d69482 Merge pull request #573 from json-schema-org/handling-nulls-in-instances bd653f34 fixed findings by julian eab34ba6 fix `prefixItems` tests to actually use it (instead of `items`, copy-paste error) 6680a003 fixed typo in `type` declaration: surround with quotes 257f5220 added null-handling tests for unevaluatedItems e3c007dd added null-handling tests for unevaluatedProperties 3d3bdf4e added null-handling tests for properties 54cc5703 added null-handling tests for patternProperties 28419842 added null-handling tests for contains 4d1a916a added null-handling tests for additionalItems 6e47a99a added null-handling tests for prefixItems; fixed indentation on previous commit 761d4b2b added null-handling tests for array-form items 6315a51d added null-handling tests for single-form items 278e5b3b added null-handling tests for additionalProperties bce6b82a Set up default reviewers (the whole test suite team). 9cb7da92 Merge pull request #564 from json-schema-org/sanity-check-terminology 2a316683 Merge pull request #569 from spacether/feat_adds_new_python_consumer fae0017d Removes idea files 8af12a3f Adds python-experimental to the users list c7a0f3e9 Reconcile terminology in the sanity checker with the README git-subtree-dir: json git-subtree-split: 69acf52990b004240839ae19b4bec8fb01d50876
I'm working on some schema canonicalisation and intersection logic for
hypothesis-jsonschema
, and encountered the surprising-to-me property thatjsonschema
sometimes considers0 == False
(and similarly1 == True
):According to the core spec, instances are only equal if they are of the same type.
(and there is only one number type in JSON, so
1 == 1.0
)The validation spec doesn't actually say anything about how value equality (ctrl-f "equal") should be defined, but I certainly found this surprising and theuniqueItems
message convinced me to report it.The text was updated successfully, but these errors were encountered: