Skip to content

Overriding reserved NamedTuple methods #2924

Description

@lolpack

Overriding reserved methods like _asdict and _make in a NamedTuple subclass should produce an error.

from typing import NamedTuple

class Record(NamedTuple):
    name: str
    value: int

    def _asdict(self) -> dict[str, object]:
        return {}

    @classmethod
    def _make(cls, iterable: object) -> "Record":
        return cls("", 0)

Sandbox: Pyrefly

Activity

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

    needs-discussionAn issue where it's not clear whether there is a bug or we are behaving as expected.typechecking

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions