mypy icon indicating copy to clipboard operation
mypy copied to clipboard

[1.16 regression] Incompatible types error when using `Enum`s of a `NamedTuple`

Open pcavalar opened this issue 7 months ago • 1 comments

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

pcavalar avatar Jun 06 '25 08:06 pcavalar

cc @sobolevn

A5rocks avatar Jun 06 '25 14:06 A5rocks