ordered_enum
ordered_enum copied to clipboard
Correctly support `>=` and `<=` for type checking
When using mypy, > and < comparison is considered valid:
from ordered_enum import OrderedEnum
class TestEnum(OrderedEnum):
ONE = 1
TWO = 2
THREE = 3
if TestEnum.THREE > TestEnum.TWO:
pass
Success: no issues found in 1 source file
But if I use >= or <=, even though it works correctly, mypy reports an error:
from ordered_enum import OrderedEnum
class TestEnum(OrderedEnum):
ONE = 1
TWO = 2
THREE = 3
if TestEnum.THREE >= TestEnum.TWO:
pass
test.py:10: error: Unsupported left operand type for >= ("TestEnum") [operator]
Found 1 error in 1 file (checked 1 source file)
Thanks for the report @YaraslauZhylko! I'm not totally sure why that is: the APIs in this package use @functools.total_ordering, which should be handled by mypy as of https://github.com/python/mypy/pull/7831.
It's possible that the underlying problem here is that there are no annotations at all in the package, really. I can look into that later today or tomorrow.