Skip to content

Commit 04afa49

Browse files
cdce8phauntsaninjaAlexWaygood
authored
Sync typeshed (#19194)
Source commit: python/typeshed@5a3c495 --------- Co-authored-by: Shantanu <[email protected]> Co-authored-by: AlexWaygood <[email protected]>
1 parent 21d3090 commit 04afa49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+741
-216
lines changed

mypy/fastparse.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,6 @@ def visit_Constant(self, n: Constant) -> Type:
20602060
contents = bytes_to_human_readable_repr(val)
20612061
return RawExpressionType(contents, "builtins.bytes", self.line, column=n.col_offset)
20622062
# Everything else is invalid.
2063-
return self.invalid_type(n)
20642063

20652064
# UnaryOp(op, operand)
20662065
def visit_UnaryOp(self, n: UnaryOp) -> Type:

mypy/typeshed/stdlib/_asyncio.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,4 @@ if sys.version_info >= (3, 12):
107107
if sys.version_info >= (3, 14):
108108
def future_discard_from_awaited_by(future: Future[Any], waiter: Future[Any], /) -> None: ...
109109
def future_add_to_awaited_by(future: Future[Any], waiter: Future[Any], /) -> None: ...
110+
def all_tasks(loop: AbstractEventLoop | None = None) -> set[Task[Any]]: ...

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class _CData:
7575
_objects: Mapping[Any, int] | None
7676
def __buffer__(self, flags: int, /) -> memoryview: ...
7777
def __ctypes_from_outparam__(self, /) -> Self: ...
78+
if sys.version_info >= (3, 14):
79+
__pointer_type__: type
7880

7981
# this is a union of all the subclasses of _CData, which is useful because of
8082
# the methods that are present on each of those subclasses which are not present

mypy/typeshed/stdlib/_curses.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ def has_colors() -> bool: ...
304304
if sys.version_info >= (3, 10):
305305
def has_extended_color_support() -> bool: ...
306306

307+
if sys.version_info >= (3, 14):
308+
def assume_default_colors(fg: int, bg: int, /) -> None: ...
309+
307310
def has_ic() -> bool: ...
308311
def has_il() -> bool: ...
309312
def has_key(key: int, /) -> bool: ...

mypy/typeshed/stdlib/_heapq.pyi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
import sys
12
from typing import Any, Final, TypeVar
23

3-
_T = TypeVar("_T")
4+
_T = TypeVar("_T") # list items must be comparable
45

56
__about__: Final[str]
67

7-
def heapify(heap: list[Any], /) -> None: ...
8+
def heapify(heap: list[Any], /) -> None: ... # list items must be comparable
89
def heappop(heap: list[_T], /) -> _T: ...
910
def heappush(heap: list[_T], item: _T, /) -> None: ...
1011
def heappushpop(heap: list[_T], item: _T, /) -> _T: ...
1112
def heapreplace(heap: list[_T], item: _T, /) -> _T: ...
13+
14+
if sys.version_info >= (3, 14):
15+
def heapify_max(heap: list[Any], /) -> None: ... # list items must be comparable
16+
def heappop_max(heap: list[_T], /) -> _T: ...
17+
def heappush_max(heap: list[_T], item: _T, /) -> None: ...
18+
def heappushpop_max(heap: list[_T], item: _T, /) -> _T: ...
19+
def heapreplace_max(heap: list[_T], item: _T, /) -> _T: ...

mypy/typeshed/stdlib/_imp.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ from importlib.machinery import ModuleSpec
55
from typing import Any
66

77
check_hash_based_pycs: str
8+
if sys.version_info >= (3, 14):
9+
pyc_magic_number_token: int
810

911
def source_hash(key: int, source: ReadableBuffer) -> bytes: ...
1012
def create_builtin(spec: ModuleSpec, /) -> types.ModuleType: ...

mypy/typeshed/stdlib/_posixsubprocess.pyi

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,56 @@ from collections.abc import Callable, Sequence
44
from typing import SupportsIndex
55

66
if sys.platform != "win32":
7-
def fork_exec(
8-
args: Sequence[StrOrBytesPath] | None,
9-
executable_list: Sequence[bytes],
10-
close_fds: bool,
11-
pass_fds: tuple[int, ...],
12-
cwd: str,
13-
env: Sequence[bytes] | None,
14-
p2cread: int,
15-
p2cwrite: int,
16-
c2pread: int,
17-
c2pwrite: int,
18-
errread: int,
19-
errwrite: int,
20-
errpipe_read: int,
21-
errpipe_write: int,
22-
restore_signals: int,
23-
call_setsid: int,
24-
pgid_to_set: int,
25-
gid: SupportsIndex | None,
26-
extra_groups: list[int] | None,
27-
uid: SupportsIndex | None,
28-
child_umask: int,
29-
preexec_fn: Callable[[], None],
30-
allow_vfork: bool,
31-
/,
32-
) -> int: ...
7+
if sys.version_info >= (3, 14):
8+
def fork_exec(
9+
args: Sequence[StrOrBytesPath] | None,
10+
executable_list: Sequence[bytes],
11+
close_fds: bool,
12+
pass_fds: tuple[int, ...],
13+
cwd: str,
14+
env: Sequence[bytes] | None,
15+
p2cread: int,
16+
p2cwrite: int,
17+
c2pread: int,
18+
c2pwrite: int,
19+
errread: int,
20+
errwrite: int,
21+
errpipe_read: int,
22+
errpipe_write: int,
23+
restore_signals: int,
24+
call_setsid: int,
25+
pgid_to_set: int,
26+
gid: SupportsIndex | None,
27+
extra_groups: list[int] | None,
28+
uid: SupportsIndex | None,
29+
child_umask: int,
30+
preexec_fn: Callable[[], None],
31+
/,
32+
) -> int: ...
33+
else:
34+
def fork_exec(
35+
args: Sequence[StrOrBytesPath] | None,
36+
executable_list: Sequence[bytes],
37+
close_fds: bool,
38+
pass_fds: tuple[int, ...],
39+
cwd: str,
40+
env: Sequence[bytes] | None,
41+
p2cread: int,
42+
p2cwrite: int,
43+
c2pread: int,
44+
c2pwrite: int,
45+
errread: int,
46+
errwrite: int,
47+
errpipe_read: int,
48+
errpipe_write: int,
49+
restore_signals: bool,
50+
call_setsid: bool,
51+
pgid_to_set: int,
52+
gid: SupportsIndex | None,
53+
extra_groups: list[int] | None,
54+
uid: SupportsIndex | None,
55+
child_umask: int,
56+
preexec_fn: Callable[[], None],
57+
allow_vfork: bool,
58+
/,
59+
) -> int: ...

mypy/typeshed/stdlib/_thread.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class RLock:
1818
def release(self) -> None: ...
1919
__enter__ = acquire
2020
def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ...
21+
if sys.version_info >= (3, 14):
22+
def locked(self) -> bool: ...
2123

2224
if sys.version_info >= (3, 13):
2325
@final
@@ -105,6 +107,9 @@ _excepthook: Callable[[_ExceptHookArgs], Any]
105107
if sys.version_info >= (3, 12):
106108
def daemon_threads_allowed() -> bool: ...
107109

110+
if sys.version_info >= (3, 14):
111+
def set_name(name: str) -> None: ...
112+
108113
class _local:
109114
def __getattribute__(self, name: str, /) -> Any: ...
110115
def __setattr__(self, name: str, value: Any, /) -> None: ...

mypy/typeshed/stdlib/_tkinter.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class TkappType:
7777
def globalgetvar(self, *args, **kwargs): ...
7878
def globalsetvar(self, *args, **kwargs): ...
7979
def globalunsetvar(self, *args, **kwargs): ...
80-
def interpaddr(self): ...
80+
def interpaddr(self) -> int: ...
8181
def loadtk(self) -> None: ...
8282
def mainloop(self, threshold: int = 0, /): ...
8383
def quit(self): ...

mypy/typeshed/stdlib/_typeshed/__init__.pyi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,6 @@ class SupportsGetItemBuffer(SliceableBuffer, IndexableBuffer, Protocol):
298298

299299
class SizedBuffer(Sized, Buffer, Protocol): ...
300300

301-
# for compatibility with third-party stubs that may use this
302-
_BufferWithLen: TypeAlias = SizedBuffer # not stable # noqa: Y047
303-
304301
ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType]
305302
OptExcInfo: TypeAlias = ExcInfo | tuple[None, None, None]
306303

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,7 @@ class HelpFormatter:
283283

284284
if sys.version_info >= (3, 14):
285285
def __init__(
286-
self,
287-
prog: str,
288-
indent_increment: int = 2,
289-
max_help_position: int = 24,
290-
width: int | None = None,
291-
prefix_chars: str = "-",
292-
color: bool = False,
286+
self, prog: str, indent_increment: int = 2, max_help_position: int = 24, width: int | None = None, color: bool = False
293287
) -> None: ...
294288
else:
295289
def __init__(

mypy/typeshed/stdlib/ast.pyi

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,20 +1095,28 @@ if sys.version_info >= (3, 14):
10951095
**kwargs: Unpack[_Attributes],
10961096
) -> Self: ...
10971097

1098+
if sys.version_info >= (3, 10):
1099+
from types import EllipsisType
1100+
1101+
_ConstantValue: typing_extensions.TypeAlias = str | bytes | bool | int | float | complex | None | EllipsisType
1102+
else:
1103+
# Rely on builtins.ellipsis
1104+
_ConstantValue: typing_extensions.TypeAlias = str | bytes | bool | int | float | complex | None | ellipsis # noqa: F821
1105+
10981106
class Constant(expr):
10991107
if sys.version_info >= (3, 10):
11001108
__match_args__ = ("value", "kind")
1101-
value: Any # None, str, bytes, bool, int, float, complex, Ellipsis
1109+
value: _ConstantValue
11021110
kind: str | None
11031111
if sys.version_info < (3, 14):
11041112
# Aliases for value, for backwards compatibility
1105-
s: Any
1106-
n: int | float | complex
1113+
s: _ConstantValue
1114+
n: _ConstantValue
11071115

1108-
def __init__(self, value: Any, kind: str | None = None, **kwargs: Unpack[_Attributes]) -> None: ...
1116+
def __init__(self, value: _ConstantValue, kind: str | None = None, **kwargs: Unpack[_Attributes]) -> None: ...
11091117

11101118
if sys.version_info >= (3, 14):
1111-
def __replace__(self, *, value: Any = ..., kind: str | None = ..., **kwargs: Unpack[_Attributes]) -> Self: ...
1119+
def __replace__(self, *, value: _ConstantValue = ..., kind: str | None = ..., **kwargs: Unpack[_Attributes]) -> Self: ...
11121120

11131121
class Attribute(expr):
11141122
if sys.version_info >= (3, 10):
@@ -1429,15 +1437,19 @@ class keyword(AST):
14291437
def __replace__(self, *, arg: str | None = ..., value: expr = ..., **kwargs: Unpack[_Attributes]) -> Self: ...
14301438

14311439
class alias(AST):
1432-
lineno: int
1433-
col_offset: int
1434-
end_lineno: int | None
1435-
end_col_offset: int | None
1436-
if sys.version_info >= (3, 10):
1437-
__match_args__ = ("name", "asname")
14381440
name: str
14391441
asname: str | None
1440-
def __init__(self, name: str, asname: str | None = None, **kwargs: Unpack[_Attributes]) -> None: ...
1442+
if sys.version_info >= (3, 10):
1443+
lineno: int
1444+
col_offset: int
1445+
end_lineno: int | None
1446+
end_col_offset: int | None
1447+
if sys.version_info >= (3, 10):
1448+
__match_args__ = ("name", "asname")
1449+
if sys.version_info >= (3, 10):
1450+
def __init__(self, name: str, asname: str | None = None, **kwargs: Unpack[_Attributes]) -> None: ...
1451+
else:
1452+
def __init__(self, name: str, asname: str | None = None) -> None: ...
14411453

14421454
if sys.version_info >= (3, 14):
14431455
def __replace__(self, *, name: str = ..., asname: str | None = ..., **kwargs: Unpack[_Attributes]) -> Self: ...

mypy/typeshed/stdlib/asyncio/__init__.pyi

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ if sys.platform == "win32":
4141
"Server", # from base_events
4242
"iscoroutinefunction", # from coroutines
4343
"iscoroutine", # from coroutines
44-
"AbstractEventLoopPolicy", # from events
44+
"_AbstractEventLoopPolicy", # from events
4545
"AbstractEventLoop", # from events
4646
"AbstractServer", # from events
4747
"Handle", # from events
4848
"TimerHandle", # from events
49+
"_get_event_loop_policy", # from events
4950
"get_event_loop_policy", # from events
51+
"_set_event_loop_policy", # from events
5052
"set_event_loop_policy", # from events
5153
"get_event_loop", # from events
5254
"set_event_loop", # from events
@@ -132,9 +134,9 @@ if sys.platform == "win32":
132134
"SelectorEventLoop", # from windows_events
133135
"ProactorEventLoop", # from windows_events
134136
"IocpProactor", # from windows_events
135-
"DefaultEventLoopPolicy", # from windows_events
136-
"WindowsSelectorEventLoopPolicy", # from windows_events
137-
"WindowsProactorEventLoopPolicy", # from windows_events
137+
"_DefaultEventLoopPolicy", # from windows_events
138+
"_WindowsSelectorEventLoopPolicy", # from windows_events
139+
"_WindowsProactorEventLoopPolicy", # from windows_events
138140
"EventLoop", # from windows_events
139141
)
140142
elif sys.version_info >= (3, 13):
@@ -515,12 +517,14 @@ else:
515517
"Server", # from base_events
516518
"iscoroutinefunction", # from coroutines
517519
"iscoroutine", # from coroutines
518-
"AbstractEventLoopPolicy", # from events
520+
"_AbstractEventLoopPolicy", # from events
519521
"AbstractEventLoop", # from events
520522
"AbstractServer", # from events
521523
"Handle", # from events
522524
"TimerHandle", # from events
525+
"_get_event_loop_policy", # from events
523526
"get_event_loop_policy", # from events
527+
"_set_event_loop_policy", # from events
524528
"set_event_loop_policy", # from events
525529
"get_event_loop", # from events
526530
"set_event_loop", # from events
@@ -606,7 +610,7 @@ else:
606610
"DatagramTransport", # from transports
607611
"SubprocessTransport", # from transports
608612
"SelectorEventLoop", # from unix_events
609-
"DefaultEventLoopPolicy", # from unix_events
613+
"_DefaultEventLoopPolicy", # from unix_events
610614
"EventLoop", # from unix_events
611615
)
612616
elif sys.version_info >= (3, 13):

mypy/typeshed/stdlib/asyncio/events.pyi

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ if sys.version_info < (3, 14):
2828
# Keep asyncio.__all__ updated with any changes to __all__ here
2929
if sys.version_info >= (3, 14):
3030
__all__ = (
31-
"AbstractEventLoopPolicy",
31+
"_AbstractEventLoopPolicy",
3232
"AbstractEventLoop",
3333
"AbstractServer",
3434
"Handle",
3535
"TimerHandle",
36+
"_get_event_loop_policy",
3637
"get_event_loop_policy",
38+
"_set_event_loop_policy",
3739
"set_event_loop_policy",
3840
"get_event_loop",
3941
"set_event_loop",
@@ -600,7 +602,7 @@ class AbstractEventLoop:
600602
@abstractmethod
601603
async def shutdown_default_executor(self) -> None: ...
602604

603-
class AbstractEventLoopPolicy:
605+
class _AbstractEventLoopPolicy:
604606
@abstractmethod
605607
def get_event_loop(self) -> AbstractEventLoop: ...
606608
@abstractmethod
@@ -622,13 +624,33 @@ class AbstractEventLoopPolicy:
622624
@abstractmethod
623625
def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ...
624626

625-
class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy, metaclass=ABCMeta):
626-
def get_event_loop(self) -> AbstractEventLoop: ...
627-
def set_event_loop(self, loop: AbstractEventLoop | None) -> None: ...
628-
def new_event_loop(self) -> AbstractEventLoop: ...
627+
if sys.version_info < (3, 14):
628+
AbstractEventLoopPolicy = _AbstractEventLoopPolicy
629+
630+
if sys.version_info >= (3, 14):
631+
class _BaseDefaultEventLoopPolicy(_AbstractEventLoopPolicy, metaclass=ABCMeta):
632+
def get_event_loop(self) -> AbstractEventLoop: ...
633+
def set_event_loop(self, loop: AbstractEventLoop | None) -> None: ...
634+
def new_event_loop(self) -> AbstractEventLoop: ...
635+
636+
else:
637+
class BaseDefaultEventLoopPolicy(_AbstractEventLoopPolicy, metaclass=ABCMeta):
638+
def get_event_loop(self) -> AbstractEventLoop: ...
639+
def set_event_loop(self, loop: AbstractEventLoop | None) -> None: ...
640+
def new_event_loop(self) -> AbstractEventLoop: ...
641+
642+
if sys.version_info >= (3, 14):
643+
def _get_event_loop_policy() -> _AbstractEventLoopPolicy: ...
644+
def _set_event_loop_policy(policy: _AbstractEventLoopPolicy | None) -> None: ...
645+
@deprecated("Deprecated as of Python 3.14; will be removed in Python 3.16")
646+
def get_event_loop_policy() -> _AbstractEventLoopPolicy: ...
647+
@deprecated("Deprecated as of Python 3.14; will be removed in Python 3.16")
648+
def set_event_loop_policy(policy: _AbstractEventLoopPolicy | None) -> None: ...
649+
650+
else:
651+
def get_event_loop_policy() -> _AbstractEventLoopPolicy: ...
652+
def set_event_loop_policy(policy: _AbstractEventLoopPolicy | None) -> None: ...
629653

630-
def get_event_loop_policy() -> AbstractEventLoopPolicy: ...
631-
def set_event_loop_policy(policy: AbstractEventLoopPolicy | None) -> None: ...
632654
def set_event_loop(loop: AbstractEventLoop | None) -> None: ...
633655
def new_event_loop() -> AbstractEventLoop: ...
634656

0 commit comments

Comments
 (0)