From a434127891203cddf68cc3e1960b5a57cce124f0 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 24 May 2024 13:36:06 -0400 Subject: [PATCH 1/2] builtins: updates for py313 --- stdlib/@tests/stubtest_allowlists/py313.txt | 5 ---- stdlib/builtins.pyi | 31 +++++++++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index 6402c18c0967..59e53525b729 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -58,11 +58,6 @@ asyncio.streams.StreamWriter.__del__ bdb.Bdb.dispatch_opcode bdb.Bdb.set_stepinstr bdb.Bdb.user_opcode -builtins.IncompleteInputError -builtins.PythonFinalizationError -builtins.property.__name__ -builtins.str.format_map -builtins.str.replace codecs.backslashreplace_errors codecs.ignore_errors codecs.namereplace_errors diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index ab73371e7910..ae718b991dbd 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -461,7 +461,11 @@ class str(Sequence[str]): def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ... @overload def format(self, *args: object, **kwargs: object) -> str: ... - def format_map(self, map: _FormatMapMapping) -> str: ... + if sys.version_info >= (3, 13): + def format_map(self, /, mapping: _FormatMapMapping) -> str: ... + else: + def format_map(self, map: _FormatMapMapping, /) -> str: ... + def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... @@ -495,10 +499,20 @@ class str(Sequence[str]): def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ... @overload def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc] - @overload - def replace(self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, /) -> LiteralString: ... - @overload - def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc] + if sys.version_info >= (3, 13): + @overload + def replace( + self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1 + ) -> LiteralString: ... + @overload + def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc] + else: + @overload + def replace( + self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, / + ) -> LiteralString: ... + @overload + def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc] if sys.version_info >= (3, 9): @overload def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ... @@ -1214,6 +1228,9 @@ class property: fset: Callable[[Any, Any], None] | None fdel: Callable[[Any], None] | None __isabstractmethod__: bool + if sys.version_info >= (3, 13): + __name__: str + def __init__( self, fget: Callable[[Any], Any] | None = ..., @@ -2057,3 +2074,7 @@ if sys.version_info >= (3, 11): def split( self, condition: Callable[[_ExceptionT_co | Self], bool], / ) -> tuple[ExceptionGroup[_ExceptionT_co] | None, ExceptionGroup[_ExceptionT_co] | None]: ... + +if sys.version_info >= (3, 13): + class IncompleteInputError(SyntaxError): ... + class PythonFinalizationError(RuntimeError): ... From 52c1ee396966edf41ba7cef518da0f3ffef83b94 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 24 May 2024 15:20:53 -0400 Subject: [PATCH 2/2] address review --- stdlib/@tests/stubtest_allowlists/py313.txt | 1 + stdlib/builtins.pyi | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index 59e53525b729..23a50cbf3d0c 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -332,6 +332,7 @@ _weakref.ProxyType.__reversed__ # Doesn't really exist argparse._MutuallyExclusiveGroup.add_mutually_exclusive_group # deprecated, forwards arguments to super ast.ImportFrom.level # None on the class, but never None on instances builtins.property.__set_name__ # Doesn't actually exist +builtins.str.format_map # stubtest says `mapping` is pos-or-keyword but in reality it is pos-only collections\.UserList\.index # ignoring pos-or-keyword parameter dataclasses.KW_ONLY # white lies around defaults enum.auto.__init__ # The stub for enum.auto is nothing like the implementation diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index ae718b991dbd..53e00ec6a5a9 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -461,11 +461,7 @@ class str(Sequence[str]): def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ... @overload def format(self, *args: object, **kwargs: object) -> str: ... - if sys.version_info >= (3, 13): - def format_map(self, /, mapping: _FormatMapMapping) -> str: ... - else: - def format_map(self, map: _FormatMapMapping, /) -> str: ... - + def format_map(self, mapping: _FormatMapMapping, /) -> str: ... def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ...