From 8fa523e7e0dbc3300366a2c6dc8782e70dfc656e Mon Sep 17 00:00:00 2001 From: DetachHead <57028336+DetachHead@users.noreply.github.com> Date: Mon, 27 Jul 2026 15:16:57 +1000 Subject: [PATCH 1/2] use `LiteralString` for `sentinel` name type checkers enforce that the first argument to a sentinel is a string literal matching its name, which is enforced by the PEP: see https://peps.python.org/pep-0661/#typing currently the type checkers contain logic to enforce that the argument is a string literal, but some of this special-casing can be removed if we use `LiteralString` in the stubs --- stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 3c549d97316c..a11f4fed3b3a 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -2196,7 +2196,7 @@ if sys.version_info >= (3, 15): class sentinel: __name__: str __module__: str - def __new__(cls, name: str, /, *, repr: str | None = None) -> sentinel: ... + def __new__(cls, name: LiteralString, /, *, repr: str | None = None) -> sentinel: ... def __copy__(self, /) -> sentinel: ... def __deepcopy__(self, memo: Any, /) -> sentinel: ... # `other` can be any legal form for unions. From 1f5eab58de3bcee9ace6ecb63e0d96f0811d121e Mon Sep 17 00:00:00 2001 From: DetachHead <57028336+DetachHead@users.noreply.github.com> Date: Mon, 27 Jul 2026 16:46:22 +1000 Subject: [PATCH 2/2] update `typing_extensions.sentinel` with the same change --- stdlib/typing_extensions.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index b89d96b2be9c..2850cadfee4a 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -730,7 +730,7 @@ if sys.version_info >= (3, 15): from builtins import sentinel as sentinel else: class sentinel: - def __init__(self, name: str, /, *, repr: str | None = None) -> None: ... + def __init__(self, name: LiteralString, /, *, repr: str | None = None) -> None: ... __name__: str __module__: str if sys.version_info >= (3, 14):