cwacek/python-jsonschema-objects

__lt__ operator doesn't work with two Literals

Closed this issue · 0 comments

Describe the bug
As per title, object.some_number < object.some_other_number raises TypeError

Example Schema and code

{
  "title":"whatever",
  "test": {"type": "number"}
}

>>> whatever.test < whatever.test
>>> whatever.test <= whatever.test
>>> whatever.test >= whatever.test

Expected behaviour
Returns a boolean value

Actual behaviour
Raises TypeError because int.__lt__ doesn't know how to deal with a Literal.

Suggested fix

In Literal.__lt__(self, other), use an isinstance(Literal, other) check, compare with other._value if it's another Literal