From 2d46095e3fbda5113c51bd91cfc1be2f4990cb32 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 9 May 2025 21:04:35 +0200 Subject: [PATCH] Fix errors when type checking stdlib with Python 3.14 (#13977) --- stdlib/ast.pyi | 33 ++++++++++++++++++--------------- stdlib/asyncio/events.pyi | 4 +++- stdlib/sqlite3/__init__.pyi | 4 +++- stdlib/typing.pyi | 4 +++- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/stdlib/ast.pyi b/stdlib/ast.pyi index cb6fce435..be7788edf 100644 --- a/stdlib/ast.pyi +++ b/stdlib/ast.pyi @@ -174,6 +174,7 @@ class FunctionDef(stmt): returns: expr | None = ..., type_comment: str | None = ..., type_params: list[type_param] = ..., + **kwargs: Unpack[_Attributes], ) -> Self: ... class AsyncFunctionDef(stmt): @@ -245,11 +246,11 @@ class AsyncFunctionDef(stmt): *, name: str = ..., args: arguments = ..., - body: list[stmt], - decorator_list: list[expr], - returns: expr | None, - type_comment: str | None, - type_params: list[type_param], + body: list[stmt] = ..., + decorator_list: list[expr] = ..., + returns: expr | None = ..., + type_comment: str | None = ..., + type_params: list[type_param] = ..., ) -> Self: ... class ClassDef(stmt): @@ -301,12 +302,12 @@ class ClassDef(stmt): def __replace__( self, *, - name: str, - bases: list[expr], - keywords: list[keyword], - body: list[stmt], - decorator_list: list[expr], - type_params: list[type_param], + name: str = ..., + bases: list[expr] = ..., + keywords: list[keyword] = ..., + body: list[stmt] = ..., + decorator_list: list[expr] = ..., + type_params: list[type_param] = ..., **kwargs: Unpack[_Attributes], ) -> Self: ... @@ -377,7 +378,7 @@ if sys.version_info >= (3, 12): ) -> None: ... if sys.version_info >= (3, 14): - def __replace__( + def __replace__( # type: ignore[override] self, *, name: Name = ..., @@ -540,7 +541,9 @@ class While(stmt): def __init__(self, test: expr, body: list[stmt], orelse: list[stmt], **kwargs: Unpack[_Attributes]) -> None: ... if sys.version_info >= (3, 14): - def __replace__(self, *, test: expr, body: list[stmt], orelse: list[stmt], **kwargs: Unpack[_Attributes]) -> Self: ... + def __replace__( + self, *, test: expr = ..., body: list[stmt] = ..., orelse: list[stmt] = ..., **kwargs: Unpack[_Attributes] + ) -> Self: ... class If(stmt): if sys.version_info >= (3, 10): @@ -725,7 +728,7 @@ class Assert(stmt): def __init__(self, test: expr, msg: expr | None = None, **kwargs: Unpack[_Attributes]) -> None: ... if sys.version_info >= (3, 14): - def __replace__(self, *, test: expr, msg: expr | None, **kwargs: Unpack[_Attributes]) -> Self: ... + def __replace__(self, *, test: expr = ..., msg: expr | None = ..., **kwargs: Unpack[_Attributes]) -> Self: ... class Import(stmt): if sys.version_info >= (3, 10): @@ -775,7 +778,7 @@ class Global(stmt): def __init__(self, names: list[str], **kwargs: Unpack[_Attributes]) -> None: ... if sys.version_info >= (3, 14): - def __replace__(self, *, names: list[str], **kwargs: Unpack[_Attributes]) -> Self: ... + def __replace__(self, *, names: list[str] = ..., **kwargs: Unpack[_Attributes]) -> Self: ... class Nonlocal(stmt): if sys.version_info >= (3, 10): diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index afe912d01..af43d2f59 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -21,7 +21,9 @@ from .futures import Future from .protocols import BaseProtocol from .tasks import Task from .transports import BaseTransport, DatagramTransport, ReadTransport, SubprocessTransport, Transport, WriteTransport -from .unix_events import AbstractChildWatcher + +if sys.version_info < (3, 14): + from .unix_events import AbstractChildWatcher # Keep asyncio.__all__ updated with any changes to __all__ here if sys.version_info >= (3, 14): diff --git a/stdlib/sqlite3/__init__.pyi b/stdlib/sqlite3/__init__.pyi index b83516b4d..5d3c2330b 100644 --- a/stdlib/sqlite3/__init__.pyi +++ b/stdlib/sqlite3/__init__.pyi @@ -60,12 +60,14 @@ from sqlite3.dbapi2 import ( sqlite_version as sqlite_version, sqlite_version_info as sqlite_version_info, threadsafety as threadsafety, - version_info as version_info, ) from types import TracebackType from typing import Any, Literal, Protocol, SupportsIndex, TypeVar, final, overload, type_check_only from typing_extensions import Self, TypeAlias +if sys.version_info < (3, 14): + from sqlite3.dbapi2 import version_info as version_info + if sys.version_info >= (3, 12): from sqlite3.dbapi2 import ( LEGACY_TRANSACTION_CONTROL as LEGACY_TRANSACTION_CONTROL, diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index df753cfd9..189ff3e89 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -37,7 +37,6 @@ __all__ = [ "AsyncIterator", "Awaitable", "BinaryIO", - "ByteString", "Callable", "ChainMap", "ClassVar", @@ -106,6 +105,9 @@ __all__ = [ "runtime_checkable", ] +if sys.version_info < (3, 14): + __all__ += ["ByteString"] + if sys.version_info >= (3, 10): __all__ += ["Concatenate", "ParamSpec", "ParamSpecArgs", "ParamSpecKwargs", "TypeAlias", "TypeGuard", "is_typeddict"]