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
Overriding reserved methods like
_asdictand_makein a NamedTuple subclass should produce an error.Sandbox: Pyrefly