mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Support `enum.global_enum`

Open dscorbett opened this issue 1 year ago • 2 comments

Feature

Mypy should support module-level constants defined by enum.global_enum.

Pitch

enum.global_enum adds an enum’s members to the global namespace. Mypy reports errors for any use of global constants defined that way. It would make enum_global much more usable if mypy recognized them as defined.

Example file:

import enum

@enum.global_enum
class Example(enum.Enum):
    X = enum.auto()

print(X)

Current behavior:

$ python3.11 global_enum.py
X
$ mypy global_enum.py
global_enum.py:7: error: Name "X" is not defined  [name-defined]
Found 1 error in 1 file (checked 1 source file)

dscorbett avatar Jul 12 '24 23:07 dscorbett

This is a standard library feature. Why is it ignored?

donnillo avatar Nov 28 '25 13:11 donnillo

Mypy is a volunteer project and features get added only when someone is sufficiently motivated to contribute them.

The enum module has a lot of features and knobs, many of which are rarely used. So for a lot of people, it's not especially important to get all of it implemented.

JelleZijlstra avatar Nov 28 '25 16:11 JelleZijlstra