MCPcopy Index your code
hub / github.com/python-jsonschema/jsonschema / equal

Function equal

jsonschema/_utils.py:127–142  ·  view source on GitHub ↗

Check if two things are equal evading some Python type hierarchy semantics. Specifically in JSON Schema, evade `bool` inheriting from `int`, recursing into sequences to do the same.

(one, two)

Source from the content-addressed store, hash-verified

125
126
127def equal(one, two):
128 """
129 Check if two things are equal evading some Python type hierarchy semantics.
130
131 Specifically in JSON Schema, evade `bool` inheriting from `int`,
132 recursing into sequences to do the same.
133 """
134 if one is two:
135 return True
136 if isinstance(one, str) or isinstance(two, str):
137 return one == two
138 if isinstance(one, Sequence) and isinstance(two, Sequence):
139 return _sequence_equal(one, two)
140 if isinstance(one, Mapping) and isinstance(two, Mapping):
141 return _mapping_equal(one, two)
142 return unbool(one) == unbool(two)
143
144
145def unbool(element, true=object(), false=object()):

Callers 15

constFunction · 0.90
enumFunction · 0.90
test_noneMethod · 0.90
test_nanMethod · 0.90
test_missing_keyMethod · 0.90
test_additional_keyMethod · 0.90
test_missing_valueMethod · 0.90
test_one_noneMethod · 0.90
test_same_itemMethod · 0.90

Calls 3

_sequence_equalFunction · 0.85
_mapping_equalFunction · 0.85
unboolFunction · 0.85

Tested by 15

test_noneMethod · 0.72
test_nanMethod · 0.72
test_missing_keyMethod · 0.72
test_additional_keyMethod · 0.72
test_missing_valueMethod · 0.72
test_one_noneMethod · 0.72
test_same_itemMethod · 0.72
test_nested_equalMethod · 0.72