FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

__get__ override not recognized in NamedTuple · Issue #22193 · python/mypy · GitHub

Repository navigation

__get__ override not recognized in NamedTuple #22193

Open

Description

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL