Skip to content

Commit 3218a74

Browse files
author
mypybot
committed
Sync typeshed
Source commit: python/typeshed@cc8ca93
1 parent 8104d01 commit 3218a74

35 files changed

+368
-243
lines changed

mypy/typeshed/stdlib/_asyncio.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from asyncio.events import AbstractEventLoop
3-
from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable
3+
from collections.abc import Awaitable, Callable, Coroutine, Generator
44
from contextvars import Context
55
from types import FrameType
66
from typing import Any, Literal, TextIO, TypeVar
@@ -13,7 +13,7 @@ _T = TypeVar("_T")
1313
_T_co = TypeVar("_T_co", covariant=True)
1414
_TaskYieldType: TypeAlias = Future[object] | None
1515

16-
class Future(Awaitable[_T], Iterable[_T]):
16+
class Future(Awaitable[_T]):
1717
_state: str
1818
@property
1919
def _exception(self) -> BaseException | None: ...

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
286286
def _type_(self) -> type[_CT]: ...
287287
@_type_.setter
288288
def _type_(self, value: type[_CT]) -> None: ...
289-
raw: bytes # Note: only available if _CT == c_char
289+
# Note: only available if _CT == c_char
290+
@property
291+
def raw(self) -> bytes: ...
292+
@raw.setter
293+
def raw(self, value: ReadableBuffer) -> None: ...
290294
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
291295
# TODO These methods cannot be annotated correctly at the moment.
292296
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT

mypy/typeshed/stdlib/_decimal.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ _TrapType: TypeAlias = type[DecimalException]
2727
__version__: Final[str]
2828
__libmpdec_version__: Final[str]
2929

30-
ROUND_DOWN: Final[str]
31-
ROUND_HALF_UP: Final[str]
32-
ROUND_HALF_EVEN: Final[str]
33-
ROUND_CEILING: Final[str]
34-
ROUND_FLOOR: Final[str]
35-
ROUND_UP: Final[str]
36-
ROUND_HALF_DOWN: Final[str]
37-
ROUND_05UP: Final[str]
30+
ROUND_DOWN: Final = "ROUND_DOWN"
31+
ROUND_HALF_UP: Final = "ROUND_HALF_UP"
32+
ROUND_HALF_EVEN: Final = "ROUND_HALF_EVEN"
33+
ROUND_CEILING: Final = "ROUND_CEILING"
34+
ROUND_FLOOR: Final = "ROUND_FLOOR"
35+
ROUND_UP: Final = "ROUND_UP"
36+
ROUND_HALF_DOWN: Final = "ROUND_HALF_DOWN"
37+
ROUND_05UP: Final = "ROUND_05UP"
3838
HAVE_CONTEXTVAR: Final[bool]
3939
HAVE_THREADS: Final[bool]
4040
MAX_EMAX: Final[int]

mypy/typeshed/stdlib/_socket.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ if sys.platform == "win32":
7878
SO_EXCLUSIVEADDRUSE: int
7979
if sys.platform != "win32":
8080
SO_REUSEPORT: int
81-
if sys.platform != "darwin" or sys.version_info >= (3, 13):
81+
if sys.platform != "darwin":
8282
SO_BINDTODEVICE: int
8383

8484
if sys.platform != "win32" and sys.platform != "darwin":

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sys
22
from _typeshed import SupportsWrite, sentinel
33
from collections.abc import Callable, Generator, Iterable, Sequence
44
from re import Pattern
5-
from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload
5+
from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload
66
from typing_extensions import Self, TypeAlias, deprecated
77

88
__all__ = [
@@ -33,25 +33,14 @@ _ActionT = TypeVar("_ActionT", bound=Action)
3333
_ArgumentParserT = TypeVar("_ArgumentParserT", bound=ArgumentParser)
3434
_N = TypeVar("_N")
3535
_ActionType: TypeAlias = Callable[[str], Any] | FileType | str
36-
# more precisely, Literal["store", "store_const", "store_true",
37-
# "store_false", "append", "append_const", "count", "help", "version",
38-
# "extend"], but using this would make it hard to annotate callers
39-
# that don't use a literal argument
40-
_ActionStr: TypeAlias = str
41-
# more precisely, Literal["?", "*", "+", "...", "A...",
42-
# "==SUPPRESS=="], but using this would make it hard to annotate
43-
# callers that don't use a literal argument
44-
_NArgsStr: TypeAlias = str
4536

4637
ONE_OR_MORE: Final = "+"
4738
OPTIONAL: Final = "?"
4839
PARSER: Final = "A..."
4940
REMAINDER: Final = "..."
50-
_SUPPRESS_T = NewType("_SUPPRESS_T", str)
51-
SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is
52-
# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy
41+
SUPPRESS: Final = "==SUPPRESS=="
5342
ZERO_OR_MORE: Final = "*"
54-
_UNRECOGNIZED_ARGS_ATTR: Final[str] # undocumented
43+
_UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented
5544

5645
class ArgumentError(Exception):
5746
argument_name: str | None
@@ -86,8 +75,13 @@ class _ActionsContainer:
8675
def add_argument(
8776
self,
8877
*name_or_flags: str,
89-
action: _ActionStr | type[Action] = ...,
90-
nargs: int | _NArgsStr | _SUPPRESS_T | None = None,
78+
# str covers predefined actions ("store_true", "count", etc.)
79+
# and user registered actions via the `register` method.
80+
action: str | type[Action] = ...,
81+
# more precisely, Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="],
82+
# but using this would make it hard to annotate callers that don't use a
83+
# literal argument and for subclasses to override this method.
84+
nargs: int | str | None = None,
9185
const: Any = ...,
9286
default: Any = ...,
9387
type: _ActionType = ...,

mypy/typeshed/stdlib/asyncio/tasks.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ if sys.version_info >= (3, 12):
7979
_FutureLike: TypeAlias = Future[_T] | Awaitable[_T]
8080
else:
8181
_FutureLike: TypeAlias = Future[_T] | Generator[Any, None, _T] | Awaitable[_T]
82+
8283
_TaskYieldType: TypeAlias = Future[object] | None
8384

8485
FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED
@@ -347,7 +348,8 @@ else:
347348
*coros_or_futures: _FutureLike[_T], loop: AbstractEventLoop | None = None, return_exceptions: bool
348349
) -> Future[list[_T | BaseException]]: ...
349350

350-
def run_coroutine_threadsafe(coro: _FutureLike[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ...
351+
# unlike some asyncio apis, This does strict runtime checking of actually being a coroutine, not of any future-like.
352+
def run_coroutine_threadsafe(coro: Coroutine[Any, Any, _T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ...
351353

352354
if sys.version_info >= (3, 10):
353355
def shield(arg: _FutureLike[_T]) -> Future[_T]: ...

mypy/typeshed/stdlib/bdb.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
from _typeshed import ExcInfo, TraceFunction, Unused
3-
from collections.abc import Callable, Iterable, Mapping
3+
from collections.abc import Callable, Iterable, Iterator, Mapping
4+
from contextlib import contextmanager
45
from types import CodeType, FrameType, TracebackType
56
from typing import IO, Any, Final, SupportsInt, TypeVar
67
from typing_extensions import ParamSpec
@@ -30,6 +31,10 @@ class Bdb:
3031
def __init__(self, skip: Iterable[str] | None = None) -> None: ...
3132
def canonic(self, filename: str) -> str: ...
3233
def reset(self) -> None: ...
34+
if sys.version_info >= (3, 12):
35+
@contextmanager
36+
def set_enterframe(self, frame: FrameType) -> Iterator[None]: ...
37+
3338
def trace_dispatch(self, frame: FrameType, event: str, arg: Any) -> TraceFunction: ...
3439
def dispatch_line(self, frame: FrameType) -> TraceFunction: ...
3540
def dispatch_call(self, frame: FrameType, arg: None) -> TraceFunction: ...
@@ -73,7 +78,7 @@ class Bdb:
7378
def get_file_breaks(self, filename: str) -> list[Breakpoint]: ...
7479
def get_all_breaks(self) -> list[Breakpoint]: ...
7580
def get_stack(self, f: FrameType | None, t: TracebackType | None) -> tuple[list[tuple[FrameType, int]], int]: ...
76-
def format_stack_entry(self, frame_lineno: int, lprefix: str = ": ") -> str: ...
81+
def format_stack_entry(self, frame_lineno: tuple[FrameType, int], lprefix: str = ": ") -> str: ...
7782
def run(
7883
self, cmd: str | CodeType, globals: dict[str, Any] | None = None, locals: Mapping[str, Any] | None = None
7984
) -> None: ...

0 commit comments

Comments
 (0)