woodruffw / woodruffw/ordered_enum

Correctly support `>=` and `<=` for type checking

Open
#38 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
31
Forks
3
Avg merge
23h 14m
Merged PRs (30d)
4

Description

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)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the two Python examples and mypy, comparing the existing behavior for > and < with >= and <=. Inspect the OrderedEnum implementation and its type-checking behavior; done means mypy accepts both inclusive comparisons while the runtime comparisons continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.