[1.16 regression] Incompatible types error when using `Enum`s of a `NamedTuple`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Seeing this regression on mypy 1.16 with Enums of NamedTuples values.
Note: Enums of plain classes or dataclasses work as expected.
To Reproduce
https://mypy-play.net/?mypy=1.16.0&python=3.13&flags=strict&gist=2c5d8ca22757aee67d917d8fec20ad7f
from enum import Enum
from typing import NamedTuple
class Foo(NamedTuple):
pass
class FooEnum(Foo, Enum):
ITEM = Foo()
foo: Foo = FooEnum.ITEM # works on 1.15 but not 1.16
Actual Behavior
error: Incompatible types in assignment (expression has type "FooEnum", variable has type "Foo") [assignment]
Your Environment
- Mypy version used: 1.16
- Mypy command-line flags: defaults
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.13
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 with the linked mypy-play reproduction and the embedded Foo/FooEnum snippet, comparing mypy 1.15 with 1.16 under Python 3.13. Trace the type-checking path for Enum members inheriting from NamedTuple. Done means the assignment is accepted again and regression coverage verifies that plain classes and dataclasses remain unaffected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100