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)
| 125 | |
| 126 | |
| 127 | def 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 | |
| 145 | def unbool(element, true=object(), false=object()): |