Skip to content

Commit 9871771

Browse files
Sync typeshed (#17458)
Source commit: python/typeshed@dcab6e8
1 parent c346c54 commit 9871771

12 files changed

+347
-191
lines changed

mypy/typeshed/stdlib/VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ _dummy_thread: 3.0-3.8
3434
_dummy_threading: 3.0-3.8
3535
_heapq: 3.0-
3636
_imp: 3.0-
37+
_interpchannels: 3.13-
3738
_json: 3.0-
3839
_locale: 3.0-
3940
_lsprof: 3.0-
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from _typeshed import structseq
2+
from typing import Final, Literal, SupportsIndex, final
3+
from typing_extensions import Buffer, Self
4+
5+
class ChannelError(RuntimeError): ...
6+
class ChannelClosedError(ChannelError): ...
7+
class ChannelEmptyError(ChannelError): ...
8+
class ChannelNotEmptyError(ChannelError): ...
9+
class ChannelNotFoundError(ChannelError): ...
10+
11+
# Mark as final, since instantiating ChannelID is not supported.
12+
@final
13+
class ChannelID:
14+
@property
15+
def end(self) -> Literal["send", "recv", "both"]: ...
16+
@property
17+
def send(self) -> Self: ...
18+
@property
19+
def recv(self) -> Self: ...
20+
def __eq__(self, other: object) -> bool: ...
21+
def __ge__(self, other: ChannelID) -> bool: ...
22+
def __gt__(self, other: ChannelID) -> bool: ...
23+
def __hash__(self) -> int: ...
24+
def __index__(self) -> int: ...
25+
def __int__(self) -> int: ...
26+
def __le__(self, other: ChannelID) -> bool: ...
27+
def __lt__(self, other: ChannelID) -> bool: ...
28+
def __ne__(self, other: object) -> bool: ...
29+
30+
@final
31+
class ChannelInfo(structseq[int], tuple[bool, bool, bool, int, int, int, int, int]):
32+
__match_args__: Final = (
33+
"open",
34+
"closing",
35+
"closed",
36+
"count",
37+
"num_interp_send",
38+
"num_interp_send_released",
39+
"num_interp_recv",
40+
"num_interp_recv_released",
41+
)
42+
@property
43+
def open(self) -> bool: ...
44+
@property
45+
def closing(self) -> bool: ...
46+
@property
47+
def closed(self) -> bool: ...
48+
@property
49+
def count(self) -> int: ... # type: ignore[override]
50+
@property
51+
def num_interp_send(self) -> int: ...
52+
@property
53+
def num_interp_send_released(self) -> int: ...
54+
@property
55+
def num_interp_recv(self) -> int: ...
56+
@property
57+
def num_interp_recv_released(self) -> int: ...
58+
@property
59+
def num_interp_both(self) -> int: ...
60+
@property
61+
def num_interp_both_recv_released(self) -> int: ...
62+
@property
63+
def num_interp_both_send_released(self) -> int: ...
64+
@property
65+
def num_interp_both_released(self) -> int: ...
66+
@property
67+
def recv_associated(self) -> bool: ...
68+
@property
69+
def recv_released(self) -> bool: ...
70+
@property
71+
def send_associated(self) -> bool: ...
72+
@property
73+
def send_released(self) -> bool: ...
74+
75+
def create() -> ChannelID: ...
76+
def destroy(cid: SupportsIndex) -> None: ...
77+
def list_all() -> list[ChannelID]: ...
78+
def list_interpreters(cid: SupportsIndex, *, send: bool) -> list[int]: ...
79+
def send(cid: SupportsIndex, obj: object, *, blocking: bool = True, timeout: float | None = None) -> None: ...
80+
def send_buffer(cid: SupportsIndex, obj: Buffer, *, blocking: bool = True, timeout: float | None = None) -> None: ...
81+
def recv(cid: SupportsIndex, default: object = ...) -> object: ...
82+
def close(cid: SupportsIndex, *, send: bool = False, recv: bool = False) -> None: ...
83+
def get_info(cid: SupportsIndex) -> ChannelInfo: ...
84+
def release(cid: SupportsIndex, *, send: bool = False, recv: bool = False, force: bool = False) -> None: ...

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ _T = TypeVar("_T")
3232
_ActionT = TypeVar("_ActionT", bound=Action)
3333
_ArgumentParserT = TypeVar("_ArgumentParserT", bound=ArgumentParser)
3434
_N = TypeVar("_N")
35+
_ActionType: TypeAlias = Callable[[str], Any] | FileType | str
3536
# more precisely, Literal["store", "store_const", "store_true",
3637
# "store_false", "append", "append_const", "count", "help", "version",
3738
# "extend"], but using this would make it hard to annotate callers
@@ -89,7 +90,7 @@ class _ActionsContainer:
8990
nargs: int | _NArgsStr | _SUPPRESS_T | None = None,
9091
const: Any = ...,
9192
default: Any = ...,
92-
type: Callable[[str], _T] | FileType = ...,
93+
type: _ActionType = ...,
9394
choices: Iterable[_T] | None = ...,
9495
required: bool = ...,
9596
help: str | None = ...,
@@ -313,7 +314,7 @@ class Action(_AttributeHolder):
313314
nargs: int | str | None
314315
const: Any
315316
default: Any
316-
type: Callable[[str], Any] | FileType | None
317+
type: _ActionType | None
317318
choices: Iterable[Any] | None
318319
required: bool
319320
help: str | None
@@ -699,6 +700,7 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]):
699700
add_help: bool = ...,
700701
allow_abbrev: bool = ...,
701702
exit_on_error: bool = ...,
703+
**kwargs: Any, # Accepting any additional kwargs for custom parser classes
702704
) -> _ArgumentParserT: ...
703705
elif sys.version_info >= (3, 9):
704706
def add_parser(
@@ -721,6 +723,7 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]):
721723
add_help: bool = ...,
722724
allow_abbrev: bool = ...,
723725
exit_on_error: bool = ...,
726+
**kwargs: Any, # Accepting any additional kwargs for custom parser classes
724727
) -> _ArgumentParserT: ...
725728
else:
726729
def add_parser(
@@ -742,6 +745,7 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]):
742745
conflict_handler: str = ...,
743746
add_help: bool = ...,
744747
allow_abbrev: bool = ...,
748+
**kwargs: Any, # Accepting any additional kwargs for custom parser classes
745749
) -> _ArgumentParserT: ...
746750

747751
def _get_subactions(self) -> list[Action]: ...

mypy/typeshed/stdlib/asyncio/events.pyi

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,40 @@ from .tasks import Task
1616
from .transports import BaseTransport, DatagramTransport, ReadTransport, SubprocessTransport, Transport, WriteTransport
1717
from .unix_events import AbstractChildWatcher
1818

19-
__all__ = (
20-
"AbstractEventLoopPolicy",
21-
"AbstractEventLoop",
22-
"AbstractServer",
23-
"Handle",
24-
"TimerHandle",
25-
"get_event_loop_policy",
26-
"set_event_loop_policy",
27-
"get_event_loop",
28-
"set_event_loop",
29-
"new_event_loop",
30-
"get_child_watcher",
31-
"set_child_watcher",
32-
"_set_running_loop",
33-
"get_running_loop",
34-
"_get_running_loop",
35-
)
19+
if sys.version_info >= (3, 14):
20+
__all__ = (
21+
"AbstractEventLoopPolicy",
22+
"AbstractEventLoop",
23+
"AbstractServer",
24+
"Handle",
25+
"TimerHandle",
26+
"get_event_loop_policy",
27+
"set_event_loop_policy",
28+
"get_event_loop",
29+
"set_event_loop",
30+
"new_event_loop",
31+
"_set_running_loop",
32+
"get_running_loop",
33+
"_get_running_loop",
34+
)
35+
else:
36+
__all__ = (
37+
"AbstractEventLoopPolicy",
38+
"AbstractEventLoop",
39+
"AbstractServer",
40+
"Handle",
41+
"TimerHandle",
42+
"get_event_loop_policy",
43+
"set_event_loop_policy",
44+
"get_event_loop",
45+
"set_event_loop",
46+
"new_event_loop",
47+
"get_child_watcher",
48+
"set_child_watcher",
49+
"_set_running_loop",
50+
"get_running_loop",
51+
"_get_running_loop",
52+
)
3653

3754
_T = TypeVar("_T")
3855
_Ts = TypeVarTuple("_Ts")
@@ -541,18 +558,19 @@ class AbstractEventLoopPolicy:
541558
@abstractmethod
542559
def new_event_loop(self) -> AbstractEventLoop: ...
543560
# Child processes handling (Unix only).
544-
if sys.version_info >= (3, 12):
545-
@abstractmethod
546-
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
547-
def get_child_watcher(self) -> AbstractChildWatcher: ...
548-
@abstractmethod
549-
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
550-
def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ...
551-
else:
552-
@abstractmethod
553-
def get_child_watcher(self) -> AbstractChildWatcher: ...
554-
@abstractmethod
555-
def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ...
561+
if sys.version_info < (3, 14):
562+
if sys.version_info >= (3, 12):
563+
@abstractmethod
564+
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
565+
def get_child_watcher(self) -> AbstractChildWatcher: ...
566+
@abstractmethod
567+
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
568+
def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ...
569+
else:
570+
@abstractmethod
571+
def get_child_watcher(self) -> AbstractChildWatcher: ...
572+
@abstractmethod
573+
def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ...
556574

557575
class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy, metaclass=ABCMeta):
558576
def get_event_loop(self) -> AbstractEventLoop: ...
@@ -565,15 +583,16 @@ def get_event_loop() -> AbstractEventLoop: ...
565583
def set_event_loop(loop: AbstractEventLoop | None) -> None: ...
566584
def new_event_loop() -> AbstractEventLoop: ...
567585

568-
if sys.version_info >= (3, 12):
569-
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
570-
def get_child_watcher() -> AbstractChildWatcher: ...
571-
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
572-
def set_child_watcher(watcher: AbstractChildWatcher) -> None: ...
586+
if sys.version_info < (3, 14):
587+
if sys.version_info >= (3, 12):
588+
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
589+
def get_child_watcher() -> AbstractChildWatcher: ...
590+
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
591+
def set_child_watcher(watcher: AbstractChildWatcher) -> None: ...
573592

574-
else:
575-
def get_child_watcher() -> AbstractChildWatcher: ...
576-
def set_child_watcher(watcher: AbstractChildWatcher) -> None: ...
593+
else:
594+
def get_child_watcher() -> AbstractChildWatcher: ...
595+
def set_child_watcher(watcher: AbstractChildWatcher) -> None: ...
577596

578597
def _set_running_loop(loop: AbstractEventLoop | None, /) -> None: ...
579598
def _get_running_loop() -> AbstractEventLoop: ...

mypy/typeshed/stdlib/asyncio/tasks.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ _T4 = TypeVar("_T4")
7070
_T5 = TypeVar("_T5")
7171
_T6 = TypeVar("_T6")
7272
_FT = TypeVar("_FT", bound=Future[Any])
73-
_FutureLike: TypeAlias = Future[_T] | Generator[Any, None, _T] | Awaitable[_T]
73+
if sys.version_info >= (3, 12):
74+
_FutureLike: TypeAlias = Future[_T] | Awaitable[_T]
75+
else:
76+
_FutureLike: TypeAlias = Future[_T] | Generator[Any, None, _T] | Awaitable[_T]
7477
_TaskYieldType: TypeAlias = Future[object] | None
7578

7679
FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED

0 commit comments

Comments
 (0)