Bug Report
If a descriptor is implemented as a NamedTuple, the typing information on its __get__ method does not seem to be taken into account.
To Reproduce
import typing class DescrVal: pass class ClassDescr: def __get__(self, _instance: object, _owner: type | None = None) -> DescrVal: return DescrVal() class TupleDescr(typing.NamedTuple): def __get__(self, _instance: object, _owner: type | None = None) -> DescrVal: return DescrVal() class SomeClass: class_descr = ClassDescr() tuple_descr = TupleDescr() typing.reveal_type(SomeClass.class_descr) typing.reveal_type(SomeClass.tuple_descr)
Expected Behavior
ClassDescr and TupleDescr behave identically and accessing the descriptor returns a DescrVal instance.
Actual Behavior
mypy behaves as if the __get__ override weren’t there and assumes that the descriptors returns self instead of a DescrVal instance:
test.py:19: note: Revealed type is "test.DescrVal" test.py:20: note: Revealed type is "tuple[(), fallback=test.TupleDescr]"
Your Environment
mypy 2.3.1 (also tested on 2.4.0) on Python 3.13.15.
Activity