Skip to content

Commit f85cc79

Browse files
committed
Sync typeshed
Source commit: python/typeshed@11ff7e1
1 parent 5a07358 commit f85cc79

28 files changed

Lines changed: 259 additions & 130 deletions

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, GenericAlias
66
from typing import Any, Literal, TextIO, TypeVar
@@ -11,7 +11,7 @@ _T_co = TypeVar("_T_co", covariant=True)
1111
_TaskYieldType: TypeAlias = Future[object] | None
1212

1313
@disjoint_base
14-
class Future(Awaitable[_T], Iterable[_T]):
14+
class Future(Awaitable[_T]):
1515
_state: str
1616
@property
1717
def _exception(self) -> BaseException | None: ...

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from abc import abstractmethod
66
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
77
from ctypes import CDLL, ArgumentError as ArgumentError, c_void_p
88
from types import GenericAlias
9-
from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, final, overload, type_check_only
9+
from typing import Any, ClassVar, Final, Generic, Literal, SupportsIndex, TypeVar, final, overload, type_check_only
1010
from typing_extensions import Self, TypeAlias
1111

1212
_T = TypeVar("_T")
@@ -134,7 +134,7 @@ class _Pointer(_PointerLike, _CData, Generic[_CT], metaclass=_PyCPointerType):
134134
@overload
135135
def __getitem__(self, key: int, /) -> Any: ...
136136
@overload
137-
def __getitem__(self, key: slice, /) -> list[Any]: ...
137+
def __getitem__(self, key: slice[SupportsIndex | None], /) -> list[Any]: ...
138138
def __setitem__(self, key: int, value: Any, /) -> None: ...
139139

140140
if sys.version_info < (3, 14):
@@ -320,7 +320,11 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
320320
def _type_(self) -> type[_CT]: ...
321321
@_type_.setter
322322
def _type_(self, value: type[_CT]) -> None: ...
323-
raw: bytes # Note: only available if _CT == c_char
323+
# Note: only available if _CT == c_char
324+
@property
325+
def raw(self) -> bytes: ...
326+
@raw.setter
327+
def raw(self, value: ReadableBuffer) -> None: ...
324328
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
325329
# TODO: These methods cannot be annotated correctly at the moment.
326330
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT
@@ -338,11 +342,11 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
338342
@overload
339343
def __getitem__(self, key: int, /) -> Any: ...
340344
@overload
341-
def __getitem__(self, key: slice, /) -> list[Any]: ...
345+
def __getitem__(self, key: slice[SupportsIndex | None], /) -> list[Any]: ...
342346
@overload
343347
def __setitem__(self, key: int, value: Any, /) -> None: ...
344348
@overload
345-
def __setitem__(self, key: slice, value: Iterable[Any], /) -> None: ...
349+
def __setitem__(self, key: slice[SupportsIndex | None], value: Iterable[Any], /) -> None: ...
346350
def __iter__(self) -> Iterator[Any]: ...
347351
# Can't inherit from Sized because the metaclass conflict between
348352
# Sized and _CData prevents using _CDataMeta.

mypy/typeshed/stdlib/_operator.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,20 @@ def concat(a: Sequence[_T], b: Sequence[_T], /) -> Sequence[_T]: ...
8080
def contains(a: Container[object], b: object, /) -> bool: ...
8181
def countOf(a: Iterable[object], b: object, /) -> int: ...
8282
@overload
83-
def delitem(a: MutableSequence[Any], b: SupportsIndex, /) -> None: ...
83+
def delitem(a: MutableSequence[Any], b: int, /) -> None: ...
8484
@overload
85-
def delitem(a: MutableSequence[Any], b: slice, /) -> None: ...
85+
def delitem(a: MutableSequence[Any], b: slice[int | None], /) -> None: ...
8686
@overload
8787
def delitem(a: MutableMapping[_K, Any], b: _K, /) -> None: ...
8888
@overload
89-
def getitem(a: Sequence[_T], b: slice, /) -> Sequence[_T]: ...
89+
def getitem(a: Sequence[_T], b: slice[int | None], /) -> Sequence[_T]: ...
9090
@overload
9191
def getitem(a: SupportsGetItem[_K, _V], b: _K, /) -> _V: ...
9292
def indexOf(a: Iterable[_T], b: _T, /) -> int: ...
9393
@overload
94-
def setitem(a: MutableSequence[_T], b: SupportsIndex, c: _T, /) -> None: ...
94+
def setitem(a: MutableSequence[_T], b: int, c: _T, /) -> None: ...
9595
@overload
96-
def setitem(a: MutableSequence[_T], b: slice, c: Sequence[_T], /) -> None: ...
96+
def setitem(a: MutableSequence[_T], b: slice[int | None], c: Sequence[_T], /) -> None: ...
9797
@overload
9898
def setitem(a: MutableMapping[_K, _V], b: _K, c: _V, /) -> None: ...
9999
def length_hint(obj: object, default: int = 0, /) -> int: ...

mypy/typeshed/stdlib/_socket.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ if sys.platform != "linux":
587587

588588
has_ipv6: bool
589589

590-
if sys.platform != "darwin" and sys.platform != "linux":
590+
if sys.platform != "darwin":
591591
BDADDR_ANY: Final = "00:00:00:00:00:00"
592592
BDADDR_LOCAL: Final = "00:00:00:FF:FF:FF"
593593

@@ -660,16 +660,16 @@ if sys.platform == "darwin":
660660
PF_SYSTEM: Final[int]
661661
SYSPROTO_CONTROL: Final[int]
662662

663-
if sys.platform != "darwin" and sys.platform != "linux":
663+
if sys.platform != "darwin":
664664
AF_BLUETOOTH: Final[int]
665665

666-
if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux":
666+
if sys.platform != "win32" and sys.platform != "darwin":
667667
# Linux and some BSD support is explicit in the docs
668668
# Windows and macOS do not support in practice
669669
BTPROTO_HCI: Final[int]
670670
BTPROTO_L2CAP: Final[int]
671671
BTPROTO_SCO: Final[int] # not in FreeBSD
672-
if sys.platform != "darwin" and sys.platform != "linux":
672+
if sys.platform != "darwin":
673673
BTPROTO_RFCOMM: Final[int]
674674

675675
if sys.platform == "linux":

mypy/typeshed/stdlib/_typeshed/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Utility types for typeshed
22

3-
This package and its submodules contains various common types used by
3+
This package and its submodules contain various common types used by
44
typeshed. It can also be used by packages outside typeshed, but beware
55
the API stability guarantees below.
66

mypy/typeshed/stdlib/_typeshed/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,15 @@ WriteableBuffer: TypeAlias = Buffer
300300
ReadableBuffer: TypeAlias = Buffer # stable
301301

302302
class SliceableBuffer(Buffer, Protocol):
303-
def __getitem__(self, slice: slice, /) -> Sequence[int]: ...
303+
def __getitem__(self, slice: slice[SupportsIndex | None], /) -> Sequence[int]: ...
304304

305305
class IndexableBuffer(Buffer, Protocol):
306306
def __getitem__(self, i: int, /) -> int: ...
307307

308308
class SupportsGetItemBuffer(SliceableBuffer, IndexableBuffer, Protocol):
309309
def __contains__(self, x: Any, /) -> bool: ...
310310
@overload
311-
def __getitem__(self, slice: slice, /) -> Sequence[int]: ...
311+
def __getitem__(self, slice: slice[SupportsIndex | None], /) -> Sequence[int]: ...
312312
@overload
313313
def __getitem__(self, i: int, /) -> int: ...
314314

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 3 additions & 5 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, type_check_only
5+
from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload, type_check_only
66
from typing_extensions import Self, TypeAlias, deprecated
77

88
__all__ = [
@@ -36,9 +36,7 @@ ONE_OR_MORE: Final = "+"
3636
OPTIONAL: Final = "?"
3737
PARSER: Final = "A..."
3838
REMAINDER: Final = "..."
39-
_SUPPRESS_T = NewType("_SUPPRESS_T", str)
40-
SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is
41-
# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy
39+
SUPPRESS: Final = "==SUPPRESS=="
4240
ZERO_OR_MORE: Final = "*"
4341
_UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented
4442

@@ -81,7 +79,7 @@ class _ActionsContainer:
8179
# more precisely, Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="],
8280
# but using this would make it hard to annotate callers that don't use a
8381
# literal argument and for subclasses to override this method.
84-
nargs: int | str | _SUPPRESS_T | None = None,
82+
nargs: int | str | None = None,
8583
const: Any = ...,
8684
default: Any = ...,
8785
type: _ActionType = ...,

mypy/typeshed/stdlib/array.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ class array(MutableSequence[_T]):
8080
@overload
8181
def __getitem__(self, key: SupportsIndex, /) -> _T: ...
8282
@overload
83-
def __getitem__(self, key: slice, /) -> array[_T]: ...
83+
def __getitem__(self, key: slice[SupportsIndex | None], /) -> array[_T]: ...
8484
@overload # type: ignore[override]
8585
def __setitem__(self, key: SupportsIndex, value: _T, /) -> None: ...
8686
@overload
87-
def __setitem__(self, key: slice, value: array[_T], /) -> None: ...
88-
def __delitem__(self, key: SupportsIndex | slice, /) -> None: ...
87+
def __setitem__(self, key: slice[SupportsIndex | None], value: array[_T], /) -> None: ...
88+
def __delitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> None: ...
8989
def __add__(self, value: array[_T], /) -> array[_T]: ...
9090
def __eq__(self, value: object, /) -> bool: ...
9191
def __ge__(self, value: array[_T], /) -> bool: ...

0 commit comments

Comments
 (0)