mypy does not recognise from ... import inside an IntEnum class body as producing enum members.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
mypy does not recognise from ... import inside an IntEnum class body as producing enum members. It types the members as int instead of the enum type, causing a spurious "int" has no attribute "value" error.
The same code runs correctly at runtime — Python's EnumMeta picks up the imported names as enum members.
from enum import IntEnum
class LogLevel(IntEnum):
from syslog import (
LOG_CRIT as CRITICAL,
LOG_EMERG as EMERGENCY,
LOG_ERR as ERROR,
LOG_WARNING as WARNING,
LOG_INFO as INFO,
LOG_DEBUG as DEBUG,
)
print(LogLevel.EMERGENCY.value)
Expected Behavior
No errors. LogLevel.EMERGENCY should be typed as LogLevel (or at minimum as int with .value accessible), consistent with how EnumMeta processes the class body at runtime.
Actual Behavior
demo.py:15: error: "int" has no attribute "value" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by saving the reported example as demo.py and running mypy on it to reproduce the attr-defined error. Trace the enum-member typing behavior involved in this class body, then verify that LogLevel.EMERGENCY is accepted with .value and that the example reports no errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100