Skip to content

0 should not be considered equal to False #575

@Zac-HD

Description

@Zac-HD

I'm working on some schema canonicalisation and intersection logic for hypothesis-jsonschema, and encountered the surprising-to-me property that jsonschema sometimes considers 0 == False (and similarly 1 == True):

# All of these pass:
validate(0, {"just": False})            # 0 == False
validate(False, {"enum": [0.0]})        # 0.0 == False
# Fails, "On instance: [0, 0]", despite `unbool` logic
validate([0, False], {"uniqueItems": 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 the uniqueItems message convinced me to report it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething doesn't work the way it should.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions