Skip to content

NamedTuple's _tuplegetter is not recognized #19414

@Gatsik

Description

@Gatsik

mypy parses NamedTuple class definition in the same way it parses regular class variables:

from typing import NamedTuple
from typing import reveal_type


class A(NamedTuple):
    foo: str = "foo"


reveal_type(A.foo)
a = "_" + A.foo
mypy t.py

t.py:9: note: Revealed type is "builtins.str"
Success: no issues found in 1 source file
python3 t.py

Runtime type is '_tuplegetter'
Traceback (most recent call last):
  File "D:\workspace\client\t.py", line 10, in <module>
    a = "_" + A.foo
        ~~~~^~~~~~~
TypeError: can only concatenate str (not "collections._tuplegetter") to str
mypy --version && python3 --version

mypy 1.16.1 (compiled: yes)
Python 3.13.5

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy