From 5dfe9dc1fde6e390847bb3813fdf2fed2c7c7b25 Mon Sep 17 00:00:00 2001 From: DetachHead <57028336+DetachHead@users.noreply.github.com> Date: Thu, 11 Jun 2026 13:42:39 +1000 Subject: [PATCH] add `@final` decorator to `NamedTuple` methods that can't be overridden at runtime --- stdlib/typing.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index e947df516860..054088a9bc19 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -1060,9 +1060,12 @@ class NamedTuple(tuple[Any, ...]): @deprecated("Creating a typing.NamedTuple using keyword arguments is deprecated and support will be removed in Python 3.15") def __init__(self, typename: str, fields: None = None, /, **kwargs: Any) -> None: ... + @final @classmethod def _make(cls, iterable: Iterable[Any]) -> typing_extensions.Self: ... + @final def _asdict(self) -> dict[str, Any]: ... + @final def _replace(self, **kwargs: Any) -> typing_extensions.Self: ... if sys.version_info >= (3, 13): def __replace__(self, **kwargs: Any) -> typing_extensions.Self: ...