Skip to content

Commit 2d46095

Browse files
authored
Fix errors when type checking stdlib with Python 3.14 (#13977)
1 parent 168af67 commit 2d46095

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

stdlib/ast.pyi

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class FunctionDef(stmt):
174174
returns: expr | None = ...,
175175
type_comment: str | None = ...,
176176
type_params: list[type_param] = ...,
177+
**kwargs: Unpack[_Attributes],
177178
) -> Self: ...
178179

179180
class AsyncFunctionDef(stmt):
@@ -245,11 +246,11 @@ class AsyncFunctionDef(stmt):
245246
*,
246247
name: str = ...,
247248
args: arguments = ...,
248-
body: list[stmt],
249-
decorator_list: list[expr],
250-
returns: expr | None,
251-
type_comment: str | None,
252-
type_params: list[type_param],
249+
body: list[stmt] = ...,
250+
decorator_list: list[expr] = ...,
251+
returns: expr | None = ...,
252+
type_comment: str | None = ...,
253+
type_params: list[type_param] = ...,
253254
) -> Self: ...
254255

255256
class ClassDef(stmt):
@@ -301,12 +302,12 @@ class ClassDef(stmt):
301302
def __replace__(
302303
self,
303304
*,
304-
name: str,
305-
bases: list[expr],
306-
keywords: list[keyword],
307-
body: list[stmt],
308-
decorator_list: list[expr],
309-
type_params: list[type_param],
305+
name: str = ...,
306+
bases: list[expr] = ...,
307+
keywords: list[keyword] = ...,
308+
body: list[stmt] = ...,
309+
decorator_list: list[expr] = ...,
310+
type_params: list[type_param] = ...,
310311
**kwargs: Unpack[_Attributes],
311312
) -> Self: ...
312313

@@ -377,7 +378,7 @@ if sys.version_info >= (3, 12):
377378
) -> None: ...
378379

379380
if sys.version_info >= (3, 14):
380-
def __replace__(
381+
def __replace__( # type: ignore[override]
381382
self,
382383
*,
383384
name: Name = ...,
@@ -540,7 +541,9 @@ class While(stmt):
540541
def __init__(self, test: expr, body: list[stmt], orelse: list[stmt], **kwargs: Unpack[_Attributes]) -> None: ...
541542

542543
if sys.version_info >= (3, 14):
543-
def __replace__(self, *, test: expr, body: list[stmt], orelse: list[stmt], **kwargs: Unpack[_Attributes]) -> Self: ...
544+
def __replace__(
545+
self, *, test: expr = ..., body: list[stmt] = ..., orelse: list[stmt] = ..., **kwargs: Unpack[_Attributes]
546+
) -> Self: ...
544547

545548
class If(stmt):
546549
if sys.version_info >= (3, 10):
@@ -725,7 +728,7 @@ class Assert(stmt):
725728
def __init__(self, test: expr, msg: expr | None = None, **kwargs: Unpack[_Attributes]) -> None: ...
726729

727730
if sys.version_info >= (3, 14):
728-
def __replace__(self, *, test: expr, msg: expr | None, **kwargs: Unpack[_Attributes]) -> Self: ...
731+
def __replace__(self, *, test: expr = ..., msg: expr | None = ..., **kwargs: Unpack[_Attributes]) -> Self: ...
729732

730733
class Import(stmt):
731734
if sys.version_info >= (3, 10):
@@ -775,7 +778,7 @@ class Global(stmt):
775778
def __init__(self, names: list[str], **kwargs: Unpack[_Attributes]) -> None: ...
776779

777780
if sys.version_info >= (3, 14):
778-
def __replace__(self, *, names: list[str], **kwargs: Unpack[_Attributes]) -> Self: ...
781+
def __replace__(self, *, names: list[str] = ..., **kwargs: Unpack[_Attributes]) -> Self: ...
779782

780783
class Nonlocal(stmt):
781784
if sys.version_info >= (3, 10):

stdlib/asyncio/events.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ from .futures import Future
2121
from .protocols import BaseProtocol
2222
from .tasks import Task
2323
from .transports import BaseTransport, DatagramTransport, ReadTransport, SubprocessTransport, Transport, WriteTransport
24-
from .unix_events import AbstractChildWatcher
24+
25+
if sys.version_info < (3, 14):
26+
from .unix_events import AbstractChildWatcher
2527

2628
# Keep asyncio.__all__ updated with any changes to __all__ here
2729
if sys.version_info >= (3, 14):

stdlib/sqlite3/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ from sqlite3.dbapi2 import (
6060
sqlite_version as sqlite_version,
6161
sqlite_version_info as sqlite_version_info,
6262
threadsafety as threadsafety,
63-
version_info as version_info,
6463
)
6564
from types import TracebackType
6665
from typing import Any, Literal, Protocol, SupportsIndex, TypeVar, final, overload, type_check_only
6766
from typing_extensions import Self, TypeAlias
6867

68+
if sys.version_info < (3, 14):
69+
from sqlite3.dbapi2 import version_info as version_info
70+
6971
if sys.version_info >= (3, 12):
7072
from sqlite3.dbapi2 import (
7173
LEGACY_TRANSACTION_CONTROL as LEGACY_TRANSACTION_CONTROL,

stdlib/typing.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ __all__ = [
3737
"AsyncIterator",
3838
"Awaitable",
3939
"BinaryIO",
40-
"ByteString",
4140
"Callable",
4241
"ChainMap",
4342
"ClassVar",
@@ -106,6 +105,9 @@ __all__ = [
106105
"runtime_checkable",
107106
]
108107

108+
if sys.version_info < (3, 14):
109+
__all__ += ["ByteString"]
110+
109111
if sys.version_info >= (3, 10):
110112
__all__ += ["Concatenate", "ParamSpec", "ParamSpecArgs", "ParamSpecKwargs", "TypeAlias", "TypeGuard", "is_typeddict"]
111113

0 commit comments

Comments
 (0)