Skip to content

Commit 7769d11

Browse files
committed
Updated typeshed stubs to the latest version.
1 parent c9e22a7 commit 7769d11

File tree

539 files changed

+10042
-1715
lines changed

Some content is hidden

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

539 files changed

+10042
-1715
lines changed

packages/pyright-internal/typeshed-fallback/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,59 @@ and are automatically released (multiple times a day, when needed) by
4646
Type checkers should be able to use these stub packages when installed. For more
4747
details, see the documentation for your type checker.
4848

49+
### Package versioning for third-party stubs
50+
51+
Version numbers of third-party stub packages consist of at least four parts.
52+
All parts of the stub version, except for the last part, correspond to the
53+
version of the runtime package being stubbed. For example, if the `types-foo`
54+
package has version `1.2.0.7`, this guarantees that the `types-foo` package
55+
contains stubs targeted against `foo==1.2.*` and tested against the latest
56+
version of `foo` matching that specifier. In this example, the final element
57+
of the version (7) indicates that this is the eighth revision of the stubs for
58+
`foo==1.2.*`. If an update to the stubs were pushed (but the stubs were still
59+
aiming to provide annotations for `foo==1.2.*`), then the version of
60+
`types-foo` would increment to `1.2.0.8`.
61+
62+
At typeshed, we try to keep breaking changes to a minimum. However, due to the
63+
nature of stubs, any version bump can introduce changes that might make your
64+
code fail to type check.
65+
66+
There are several strategies available for specifying the version of a stubs
67+
package you're using, each with its own tradeoffs:
68+
69+
1. Use the same bounds that you use for the package being stubbed. For example,
70+
if you use `requests>=2.30.0,<2.32`, you can use
71+
`types-requests>=2.30.0,<2.32`. This ensures that the stubs are compatible
72+
with the package you are using, but it carries a small risk of breaking
73+
type checking due to changes in the stubs.
74+
75+
Another risk of this strategy is that stubs often lag behind
76+
the package being stubbed. You might want to force the package being stubbed
77+
to a certain minimum version because it fixes a critical bug, but if
78+
correspondingly updated stubs have not been released, your type
79+
checking results may not be fully accurate.
80+
2. Pin the stubs to a known good version and update the pin from time to time
81+
(either manually, or using a tool such as dependabot or renovate).
82+
83+
For example, if you use `types-requests==2.31.0.1`, you can have confidence
84+
that upgrading dependencies will not break type checking. However, you will
85+
miss out on improvements in the stubs that could potentially improve type
86+
checking until you update the pin. This strategy also has the risk that the
87+
stubs you are using might become incompatible with the package being stubbed.
88+
3. Don't pin the stubs. This is the option that demands the least work from
89+
you when it comes to updating version pins, and has the advantage that you
90+
will automatically benefit from improved stubs whenever a new version of the
91+
stubs package is released. However, it carries the risk that the stubs
92+
become incompatible with the package being stubbed.
93+
94+
For example, if a new major version of the package is released, there's a
95+
chance the stubs might be updated to reflect the new version of the runtime
96+
package before you update the package being stubbed.
97+
98+
You can also switch between the different strategies as needed. For example,
99+
you could default to strategy (1), but fall back to strategy (2) when
100+
a problem arises that can't easily be fixed.
101+
49102
### The `_typeshed` package
50103

51104
typeshed includes a package `_typeshed` as part of the standard library.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d27426488ed48fd54290db765702685ca596c0c5
1+
658dd55c41b5c458c8b45dd72837740a4004785b

packages/pyright-internal/typeshed-fallback/stdlib/VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ imaplib: 2.7-
150150
imghdr: 2.7-
151151
imp: 2.7-3.11
152152
importlib: 2.7-
153+
importlib._abc: 3.10-
153154
importlib.metadata: 3.8-
154155
importlib.metadata._meta: 3.10-
155156
importlib.readers: 3.10-

packages/pyright-internal/typeshed-fallback/stdlib/_ctypes.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class _CDataMeta(type):
5151
# By default mypy complains about the following two methods, because strictly speaking cls
5252
# might not be a Type[_CT]. However this can never actually happen, because the only class that
5353
# uses _CDataMeta as its metaclass is _CData. So it's safe to ignore the errors here.
54-
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
55-
def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
54+
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc]
55+
def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc]
5656

5757
class _CData(metaclass=_CDataMeta):
5858
_b_base_: int

packages/pyright-internal/typeshed-fallback/stdlib/_operator.pyi

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ import sys
22
from _typeshed import SupportsGetItem
33
from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence
44
from typing import Any, AnyStr, Generic, Protocol, SupportsAbs, TypeVar, overload
5-
from typing_extensions import ParamSpec, SupportsIndex, TypeAlias, final
5+
from typing_extensions import ParamSpec, SupportsIndex, TypeAlias, TypeVarTuple, Unpack, final
66

77
_R = TypeVar("_R")
88
_T = TypeVar("_T")
99
_T_co = TypeVar("_T_co", covariant=True)
10+
_T1 = TypeVar("_T1")
11+
_T2 = TypeVar("_T2")
1012
_K = TypeVar("_K")
1113
_V = TypeVar("_V")
1214
_P = ParamSpec("_P")
15+
_Ts = TypeVarTuple("_Ts")
1316

1417
# The following protocols return "Any" instead of bool, since the comparison
1518
# operators can be overloaded to return an arbitrary object. For example,
@@ -105,22 +108,10 @@ class attrgetter(Generic[_T_co]):
105108

106109
@final
107110
class itemgetter(Generic[_T_co]):
108-
# mypy lacks support for PEP 646 https://github.com/python/mypy/issues/12280
109-
# So we have to define all of these overloads to simulate unpacking the arguments
110111
@overload
111-
def __new__(cls, item: _T_co) -> itemgetter[_T_co]: ...
112+
def __new__(cls, __item: _T) -> itemgetter[_T]: ...
112113
@overload
113-
def __new__(cls, item: _T_co, __item2: _T_co) -> itemgetter[tuple[_T_co, _T_co]]: ...
114-
@overload
115-
def __new__(cls, item: _T_co, __item2: _T_co, __item3: _T_co) -> itemgetter[tuple[_T_co, _T_co, _T_co]]: ...
116-
@overload
117-
def __new__(
118-
cls, item: _T_co, __item2: _T_co, __item3: _T_co, __item4: _T_co
119-
) -> itemgetter[tuple[_T_co, _T_co, _T_co, _T_co]]: ...
120-
@overload
121-
def __new__(
122-
cls, item: _T_co, __item2: _T_co, __item3: _T_co, __item4: _T_co, *items: _T_co
123-
) -> itemgetter[tuple[_T_co, ...]]: ...
114+
def __new__(cls, __item1: _T1, __item2: _T2, *items: Unpack[_Ts]) -> itemgetter[tuple[_T1, _T2, Unpack[_Ts]]]: ...
124115
# __key: _KT_contra in SupportsGetItem seems to be causing variance issues, ie:
125116
# TypeVar "_KT_contra@SupportsGetItem" is contravariant
126117
# "tuple[int, int]" is incompatible with protocol "SupportsIndex"

packages/pyright-internal/typeshed-fallback/stdlib/_typeshed/__init__.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,12 @@ class DataclassInstance(Protocol):
320320
# Anything that can be passed to the int/float constructors
321321
ConvertibleToInt: TypeAlias = str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc
322322
ConvertibleToFloat: TypeAlias = str | ReadableBuffer | SupportsFloat | SupportsIndex
323+
324+
# A few classes updated from Foo(str, Enum) to Foo(StrEnum). This is a convenience so these
325+
# can be accurate on all python versions without getting too wordy
326+
if sys.version_info >= (3, 11):
327+
from enum import StrEnum as StrEnum
328+
else:
329+
from enum import Enum
330+
331+
class StrEnum(str, Enum): ...

packages/pyright-internal/typeshed-fallback/stdlib/asyncio/base_events.pyi

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ from collections.abc import Callable, Iterable, Sequence
1111
from contextvars import Context
1212
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
1313
from typing import IO, Any, TypeVar, overload
14-
from typing_extensions import Literal, TypeAlias
14+
from typing_extensions import Literal, TypeAlias, TypeVarTuple, Unpack
1515

1616
if sys.version_info >= (3, 9):
1717
__all__ = ("BaseEventLoop", "Server")
1818
else:
1919
__all__ = ("BaseEventLoop",)
2020

2121
_T = TypeVar("_T")
22+
_Ts = TypeVarTuple("_Ts")
2223
_ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol)
2324
_Context: TypeAlias = dict[str, Any]
2425
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object]
@@ -71,12 +72,14 @@ class BaseEventLoop(AbstractEventLoop):
7172
def close(self) -> None: ...
7273
async def shutdown_asyncgens(self) -> None: ...
7374
# Methods scheduling callbacks. All these return Handles.
74-
def call_soon(self, callback: Callable[..., object], *args: Any, context: Context | None = None) -> Handle: ...
75+
def call_soon(
76+
self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
77+
) -> Handle: ...
7578
def call_later(
76-
self, delay: float, callback: Callable[..., object], *args: Any, context: Context | None = None
79+
self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
7780
) -> TimerHandle: ...
7881
def call_at(
79-
self, when: float, callback: Callable[..., object], *args: Any, context: Context | None = None
82+
self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
8083
) -> TimerHandle: ...
8184
def time(self) -> float: ...
8285
# Future methods
@@ -92,8 +95,10 @@ class BaseEventLoop(AbstractEventLoop):
9295
def set_task_factory(self, factory: _TaskFactory | None) -> None: ...
9396
def get_task_factory(self) -> _TaskFactory | None: ...
9497
# Methods for interacting with threads
95-
def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any, context: Context | None = None) -> Handle: ...
96-
def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Future[_T]: ...
98+
def call_soon_threadsafe(
99+
self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
100+
) -> Handle: ...
101+
def run_in_executor(self, executor: Any, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
97102
def set_default_executor(self, executor: Any) -> None: ...
98103
# Network I/O methods returning Futures.
99104
async def getaddrinfo(
@@ -441,9 +446,9 @@ class BaseEventLoop(AbstractEventLoop):
441446
errors: None = None,
442447
**kwargs: Any,
443448
) -> tuple[SubprocessTransport, _ProtocolT]: ...
444-
def add_reader(self, fd: FileDescriptorLike, callback: Callable[..., Any], *args: Any) -> None: ...
449+
def add_reader(self, fd: FileDescriptorLike, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
445450
def remove_reader(self, fd: FileDescriptorLike) -> bool: ...
446-
def add_writer(self, fd: FileDescriptorLike, callback: Callable[..., Any], *args: Any) -> None: ...
451+
def add_writer(self, fd: FileDescriptorLike, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
447452
def remove_writer(self, fd: FileDescriptorLike) -> bool: ...
448453
# The sock_* methods (and probably some others) are not actually implemented on
449454
# BaseEventLoop, only on subclasses. We list them here for now for convenience.
@@ -457,7 +462,7 @@ class BaseEventLoop(AbstractEventLoop):
457462
async def sock_recvfrom_into(self, sock: socket, buf: WriteableBuffer, nbytes: int = 0) -> tuple[int, _RetAddress]: ...
458463
async def sock_sendto(self, sock: socket, data: ReadableBuffer, address: _Address) -> int: ...
459464
# Signal handling.
460-
def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ...
465+
def add_signal_handler(self, sig: int, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
461466
def remove_signal_handler(self, sig: int) -> bool: ...
462467
# Error handlers.
463468
def set_exception_handler(self, handler: _ExceptionHandler | None) -> None: ...

packages/pyright-internal/typeshed-fallback/stdlib/asyncio/events.pyi

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from collections.abc import Callable, Coroutine, Generator, Sequence
66
from contextvars import Context
77
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
88
from typing import IO, Any, Protocol, TypeVar, overload
9-
from typing_extensions import Literal, Self, TypeAlias, deprecated
9+
from typing_extensions import Literal, Self, TypeAlias, TypeVarTuple, Unpack, deprecated
1010

1111
from . import _AwaitableLike, _CoroutineLike
1212
from .base_events import Server
@@ -56,6 +56,7 @@ else:
5656
)
5757

5858
_T = TypeVar("_T")
59+
_Ts = TypeVarTuple("_Ts")
5960
_ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol)
6061
_Context: TypeAlias = dict[str, Any]
6162
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object]
@@ -131,22 +132,24 @@ class AbstractEventLoop:
131132
# Methods scheduling callbacks. All these return Handles.
132133
if sys.version_info >= (3, 9): # "context" added in 3.9.10/3.10.2
133134
@abstractmethod
134-
def call_soon(self, callback: Callable[..., object], *args: Any, context: Context | None = None) -> Handle: ...
135+
def call_soon(
136+
self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
137+
) -> Handle: ...
135138
@abstractmethod
136139
def call_later(
137-
self, delay: float, callback: Callable[..., object], *args: Any, context: Context | None = None
140+
self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
138141
) -> TimerHandle: ...
139142
@abstractmethod
140143
def call_at(
141-
self, when: float, callback: Callable[..., object], *args: Any, context: Context | None = None
144+
self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
142145
) -> TimerHandle: ...
143146
else:
144147
@abstractmethod
145-
def call_soon(self, callback: Callable[..., object], *args: Any) -> Handle: ...
148+
def call_soon(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle: ...
146149
@abstractmethod
147-
def call_later(self, delay: float, callback: Callable[..., object], *args: Any) -> TimerHandle: ...
150+
def call_later(self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> TimerHandle: ...
148151
@abstractmethod
149-
def call_at(self, when: float, callback: Callable[..., object], *args: Any) -> TimerHandle: ...
152+
def call_at(self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> TimerHandle: ...
150153

151154
@abstractmethod
152155
def time(self) -> float: ...
@@ -173,13 +176,15 @@ class AbstractEventLoop:
173176
# Methods for interacting with threads
174177
if sys.version_info >= (3, 9): # "context" added in 3.9.10/3.10.2
175178
@abstractmethod
176-
def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any, context: Context | None = None) -> Handle: ...
179+
def call_soon_threadsafe(
180+
self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
181+
) -> Handle: ...
177182
else:
178183
@abstractmethod
179-
def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any) -> Handle: ...
184+
def call_soon_threadsafe(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle: ...
180185

181186
@abstractmethod
182-
def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Future[_T]: ...
187+
def run_in_executor(self, executor: Any, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
183188
@abstractmethod
184189
def set_default_executor(self, executor: Any) -> None: ...
185190
# Network I/O methods returning Futures.
@@ -542,11 +547,11 @@ class AbstractEventLoop:
542547
**kwargs: Any,
543548
) -> tuple[SubprocessTransport, _ProtocolT]: ...
544549
@abstractmethod
545-
def add_reader(self, fd: FileDescriptorLike, callback: Callable[..., Any], *args: Any) -> None: ...
550+
def add_reader(self, fd: FileDescriptorLike, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
546551
@abstractmethod
547552
def remove_reader(self, fd: FileDescriptorLike) -> bool: ...
548553
@abstractmethod
549-
def add_writer(self, fd: FileDescriptorLike, callback: Callable[..., Any], *args: Any) -> None: ...
554+
def add_writer(self, fd: FileDescriptorLike, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
550555
@abstractmethod
551556
def remove_writer(self, fd: FileDescriptorLike) -> bool: ...
552557
# Completion based I/O methods returning Futures prior to 3.7
@@ -569,7 +574,7 @@ class AbstractEventLoop:
569574
async def sock_sendto(self, sock: socket, data: ReadableBuffer, address: _Address) -> int: ...
570575
# Signal handling.
571576
@abstractmethod
572-
def add_signal_handler(self, sig: int, callback: Callable[..., object], *args: Any) -> None: ...
577+
def add_signal_handler(self, sig: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ...
573578
@abstractmethod
574579
def remove_signal_handler(self, sig: int) -> bool: ...
575580
# Error handlers.

packages/pyright-internal/typeshed-fallback/stdlib/asyncio/exceptions.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ else:
2121
)
2222

2323
class CancelledError(BaseException): ...
24-
class TimeoutError(Exception): ...
24+
25+
if sys.version_info >= (3, 11):
26+
from builtins import TimeoutError as TimeoutError
27+
else:
28+
class TimeoutError(Exception): ...
29+
2530
class InvalidStateError(Exception): ...
2631
class SendfileNotAvailableError(RuntimeError): ...
2732

packages/pyright-internal/typeshed-fallback/stdlib/asyncio/locks.pyi

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ from typing_extensions import Literal, Self
1010
from .events import AbstractEventLoop
1111
from .futures import Future
1212

13-
if sys.version_info >= (3, 11):
13+
if sys.version_info >= (3, 10):
1414
from .mixins import _LoopBoundMixin
15+
else:
16+
_LoopBoundMixin = object
1517

1618
if sys.version_info >= (3, 11):
1719
__all__ = ("Lock", "Event", "Condition", "Semaphore", "BoundedSemaphore", "Barrier")
@@ -44,7 +46,7 @@ else:
4446
self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None
4547
) -> None: ...
4648

47-
class Lock(_ContextManagerMixin):
49+
class Lock(_ContextManagerMixin, _LoopBoundMixin):
4850
if sys.version_info >= (3, 10):
4951
def __init__(self) -> None: ...
5052
else:
@@ -54,7 +56,7 @@ class Lock(_ContextManagerMixin):
5456
async def acquire(self) -> Literal[True]: ...
5557
def release(self) -> None: ...
5658

57-
class Event:
59+
class Event(_LoopBoundMixin):
5860
if sys.version_info >= (3, 10):
5961
def __init__(self) -> None: ...
6062
else:
@@ -65,7 +67,7 @@ class Event:
6567
def clear(self) -> None: ...
6668
async def wait(self) -> Literal[True]: ...
6769

68-
class Condition(_ContextManagerMixin):
70+
class Condition(_ContextManagerMixin, _LoopBoundMixin):
6971
if sys.version_info >= (3, 10):
7072
def __init__(self, lock: Lock | None = None) -> None: ...
7173
else:
@@ -79,7 +81,7 @@ class Condition(_ContextManagerMixin):
7981
def notify(self, n: int = 1) -> None: ...
8082
def notify_all(self) -> None: ...
8183

82-
class Semaphore(_ContextManagerMixin):
84+
class Semaphore(_ContextManagerMixin, _LoopBoundMixin):
8385
_value: int
8486
_waiters: deque[Future[Any]]
8587
if sys.version_info >= (3, 10):

0 commit comments

Comments
 (0)