Skip to content

Commit 589ad1c

Browse files
cdce8phauntsaninja
andauthored
Sync typeshed (#13831)
Source commit: python/typeshed@8b41b13 Reapply #13743 to remove use of `LiteralString`. Co-authored-by: Shantanu <[email protected]>
1 parent 0cab544 commit 589ad1c

Some content is hidden

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

43 files changed

+133
-118
lines changed

mypy/typeshed/stdlib/_dummy_threading.pyi

-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class Thread:
8686
class _DummyThread(Thread): ...
8787

8888
class Lock:
89-
def __init__(self) -> None: ...
9089
def __enter__(self) -> bool: ...
9190
def __exit__(
9291
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
@@ -96,7 +95,6 @@ class Lock:
9695
def locked(self) -> bool: ...
9796

9897
class _RLock:
99-
def __init__(self) -> None: ...
10098
def __enter__(self) -> bool: ...
10199
def __exit__(
102100
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
@@ -135,7 +133,6 @@ class Semaphore:
135133
class BoundedSemaphore(Semaphore): ...
136134

137135
class Event:
138-
def __init__(self) -> None: ...
139136
def is_set(self) -> bool: ...
140137
def set(self) -> None: ...
141138
def clear(self) -> None: ...

mypy/typeshed/stdlib/asyncio/taskgroups.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ __all__ = ["TaskGroup"]
1313
_T = TypeVar("_T")
1414

1515
class TaskGroup:
16-
def __init__(self) -> None: ...
1716
async def __aenter__(self: Self) -> Self: ...
1817
async def __aexit__(self, et: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ...
1918
def create_task(

mypy/typeshed/stdlib/asyncio/tasks.pyi

+9-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ __all__ = (
3636
)
3737

3838
_T = TypeVar("_T")
39+
_T_co = TypeVar("_T_co", covariant=True)
3940
_T1 = TypeVar("_T1")
4041
_T2 = TypeVar("_T2")
4142
_T3 = TypeVar("_T3")
@@ -265,21 +266,25 @@ else:
265266
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
266267
async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = ...) -> _T: ...
267268

268-
class Task(Future[_T], Generic[_T]):
269+
# mypy and pyright complain that a subclass of an invariant class shouldn't be covariant.
270+
# While this is true in general, here it's sort-of okay to have a covariant subclass,
271+
# since the only reason why `asyncio.Future` is invariant is the `set_result()` method,
272+
# and `asyncio.Task.set_result()` always raises.
273+
class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var]
269274
if sys.version_info >= (3, 8):
270275
def __init__(
271276
self,
272-
coro: Generator[_TaskYieldType, None, _T] | Awaitable[_T],
277+
coro: Generator[_TaskYieldType, None, _T_co] | Awaitable[_T_co],
273278
*,
274279
loop: AbstractEventLoop = ...,
275280
name: str | None = ...,
276281
) -> None: ...
277282
else:
278283
def __init__(
279-
self, coro: Generator[_TaskYieldType, None, _T] | Awaitable[_T], *, loop: AbstractEventLoop = ...
284+
self, coro: Generator[_TaskYieldType, None, _T_co] | Awaitable[_T_co], *, loop: AbstractEventLoop = ...
280285
) -> None: ...
281286
if sys.version_info >= (3, 8):
282-
def get_coro(self) -> Generator[_TaskYieldType, None, _T] | Awaitable[_T]: ...
287+
def get_coro(self) -> Generator[_TaskYieldType, None, _T_co] | Awaitable[_T_co]: ...
283288
def get_name(self) -> str: ...
284289
def set_name(self, __value: object) -> None: ...
285290

mypy/typeshed/stdlib/asyncio/unix_events.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ if sys.platform != "win32":
118118

119119
if sys.version_info >= (3, 9):
120120
class PidfdChildWatcher(AbstractChildWatcher):
121-
def __init__(self) -> None: ...
122121
def __enter__(self: Self) -> Self: ...
123122
def __exit__(
124123
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None

mypy/typeshed/stdlib/binhex.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ LINELEN: Literal[64]
1010
RUNCHAR: Literal[b"\x90"]
1111

1212
class FInfo:
13-
def __init__(self) -> None: ...
1413
Type: str
1514
Creator: str
1615
Flags: int

mypy/typeshed/stdlib/builtins.pyi

+16-17
Original file line numberDiff line numberDiff line change
@@ -1712,8 +1712,6 @@ class Exception(BaseException): ...
17121712
class StopIteration(Exception):
17131713
value: Any
17141714

1715-
_StandardError = Exception
1716-
17171715
class OSError(Exception):
17181716
errno: int
17191717
strerror: str
@@ -1728,37 +1726,38 @@ IOError = OSError
17281726
if sys.platform == "win32":
17291727
WindowsError = OSError
17301728

1731-
class ArithmeticError(_StandardError): ...
1732-
class AssertionError(_StandardError): ...
1729+
class ArithmeticError(Exception): ...
1730+
class AssertionError(Exception): ...
17331731

1734-
class AttributeError(_StandardError):
1732+
class AttributeError(Exception):
17351733
if sys.version_info >= (3, 10):
1734+
def __init__(self, *args: object, name: str | None = ..., obj: object = ...) -> None: ...
17361735
name: str
17371736
obj: object
17381737

1739-
class BufferError(_StandardError): ...
1740-
class EOFError(_StandardError): ...
1738+
class BufferError(Exception): ...
1739+
class EOFError(Exception): ...
17411740

1742-
class ImportError(_StandardError):
1741+
class ImportError(Exception):
17431742
def __init__(self, *args: object, name: str | None = ..., path: str | None = ...) -> None: ...
17441743
name: str | None
17451744
path: str | None
17461745
msg: str # undocumented
17471746

1748-
class LookupError(_StandardError): ...
1749-
class MemoryError(_StandardError): ...
1747+
class LookupError(Exception): ...
1748+
class MemoryError(Exception): ...
17501749

1751-
class NameError(_StandardError):
1750+
class NameError(Exception):
17521751
if sys.version_info >= (3, 10):
17531752
name: str
17541753

1755-
class ReferenceError(_StandardError): ...
1756-
class RuntimeError(_StandardError): ...
1754+
class ReferenceError(Exception): ...
1755+
class RuntimeError(Exception): ...
17571756

17581757
class StopAsyncIteration(Exception):
17591758
value: Any
17601759

1761-
class SyntaxError(_StandardError):
1760+
class SyntaxError(Exception):
17621761
msg: str
17631762
lineno: int | None
17641763
offset: int | None
@@ -1768,9 +1767,9 @@ class SyntaxError(_StandardError):
17681767
end_lineno: int | None
17691768
end_offset: int | None
17701769

1771-
class SystemError(_StandardError): ...
1772-
class TypeError(_StandardError): ...
1773-
class ValueError(_StandardError): ...
1770+
class SystemError(Exception): ...
1771+
class TypeError(Exception): ...
1772+
class ValueError(Exception): ...
17741773
class FloatingPointError(ArithmeticError): ...
17751774
class OverflowError(ArithmeticError): ...
17761775
class ZeroDivisionError(ArithmeticError): ...

mypy/typeshed/stdlib/codeop.pyi

-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ def compile_command(source: str, filename: str = ..., symbol: str = ...) -> Code
66

77
class Compile:
88
flags: int
9-
def __init__(self) -> None: ...
109
def __call__(self, source: str, filename: str, symbol: str) -> CodeType: ...
1110

1211
class CommandCompiler:
1312
compiler: Compile
14-
def __init__(self) -> None: ...
1513
def __call__(self, source: str, filename: str = ..., symbol: str = ...) -> CodeType | None: ...

mypy/typeshed/stdlib/concurrent/futures/_base.pyi

-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ _T = TypeVar("_T")
3535
_P = ParamSpec("_P")
3636

3737
class Future(Generic[_T]):
38-
def __init__(self) -> None: ...
3938
def cancel(self) -> bool: ...
4039
def cancelled(self) -> bool: ...
4140
def running(self) -> bool: ...
@@ -90,14 +89,12 @@ def wait(fs: Iterable[Future[_T]], timeout: float | None = ..., return_when: str
9089
class _Waiter:
9190
event: threading.Event
9291
finished_futures: list[Future[Any]]
93-
def __init__(self) -> None: ...
9492
def add_result(self, future: Future[Any]) -> None: ...
9593
def add_exception(self, future: Future[Any]) -> None: ...
9694
def add_cancelled(self, future: Future[Any]) -> None: ...
9795

9896
class _AsCompletedWaiter(_Waiter):
9997
lock: threading.Lock
100-
def __init__(self) -> None: ...
10198

10299
class _FirstCompletedWaiter(_Waiter): ...
103100

mypy/typeshed/stdlib/concurrent/futures/process.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class _ThreadWakeup:
1919
_closed: bool
2020
_reader: Connection
2121
_writer: Connection
22-
def __init__(self) -> None: ...
2322
def close(self) -> None: ...
2423
def wakeup(self) -> None: ...
2524
def clear(self) -> None: ...

mypy/typeshed/stdlib/contextlib.pyi

-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ class redirect_stderr(_RedirectStream[_T_io]): ...
137137
# In reality this is a subclass of `AbstractContextManager`;
138138
# see #7961 for why we don't do that in the stub
139139
class ExitStack(metaclass=abc.ABCMeta):
140-
def __init__(self) -> None: ...
141140
def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ...
142141
def push(self, exit: _CM_EF) -> _CM_EF: ...
143142
def callback(self, __callback: Callable[_P, _T], *args: _P.args, **kwds: _P.kwargs) -> Callable[_P, _T]: ...
@@ -156,7 +155,6 @@ _ACM_EF = TypeVar("_ACM_EF", bound=AbstractAsyncContextManager[Any] | _ExitCoroF
156155
# In reality this is a subclass of `AbstractAsyncContextManager`;
157156
# see #7961 for why we don't do that in the stub
158157
class AsyncExitStack(metaclass=abc.ABCMeta):
159-
def __init__(self) -> None: ...
160158
def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ...
161159
async def enter_async_context(self, cm: AbstractAsyncContextManager[_T]) -> _T: ...
162160
def push(self, exit: _CM_EF) -> _CM_EF: ...

mypy/typeshed/stdlib/csv.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,5 @@ class DictWriter(Generic[_T]):
146146

147147
class Sniffer:
148148
preferred: list[str]
149-
def __init__(self) -> None: ...
150149
def sniff(self, sample: str, delimiters: str | None = ...) -> type[Dialect]: ...
151150
def has_header(self, sample: str) -> bool: ...

mypy/typeshed/stdlib/dataclasses.pyi

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import types
44
from builtins import type as Type # alias to avoid name clashes with fields named "type"
55
from collections.abc import Callable, Iterable, Mapping
66
from typing import Any, Generic, Protocol, TypeVar, overload
7-
from typing_extensions import Literal
7+
from typing_extensions import Literal, TypeAlias
88

99
if sys.version_info >= (3, 9):
1010
from types import GenericAlias
@@ -217,7 +217,14 @@ def is_dataclass(obj: Any) -> bool: ...
217217

218218
class FrozenInstanceError(AttributeError): ...
219219

220-
class InitVar(Generic[_T]):
220+
if sys.version_info >= (3, 9):
221+
_InitVarMeta: TypeAlias = type
222+
else:
223+
class _InitVarMeta(type):
224+
# Not used, instead `InitVar.__class_getitem__` is called.
225+
def __getitem__(self, params: Any) -> InitVar[Any]: ...
226+
227+
class InitVar(Generic[_T], metaclass=_InitVarMeta):
221228
type: Type[_T]
222229
def __init__(self, type: Type[_T]) -> None: ...
223230
if sys.version_info >= (3, 9):

mypy/typeshed/stdlib/email/contentmanager.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from email.message import Message
33
from typing import Any
44

55
class ContentManager:
6-
def __init__(self) -> None: ...
76
def get_content(self, msg: Message, *args: Any, **kw: Any) -> Any: ...
87
def set_content(self, msg: Message, obj: Any, *args: Any, **kw: Any) -> Any: ...
98
def add_get_handler(self, key: str, handler: Callable[..., Any]) -> None: ...

mypy/typeshed/stdlib/formatter.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class AbstractFormatter:
6464
def assert_line_data(self, flag: int = ...) -> None: ...
6565

6666
class NullWriter:
67-
def __init__(self) -> None: ...
6867
def flush(self) -> None: ...
6968
def new_alignment(self, align: str | None) -> None: ...
7069
def new_font(self, font: _FontType) -> None: ...

mypy/typeshed/stdlib/importlib/abc.pyi

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import sys
22
import types
3-
from _typeshed import (
4-
OpenBinaryMode,
5-
OpenBinaryModeReading,
6-
OpenBinaryModeUpdating,
7-
OpenBinaryModeWriting,
8-
OpenTextMode,
9-
StrOrBytesPath,
10-
StrPath,
11-
)
3+
from _typeshed import OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode
124
from abc import ABCMeta, abstractmethod
135
from collections.abc import Iterator, Mapping, Sequence
146
from importlib.machinery import ModuleSpec
@@ -93,9 +85,9 @@ class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta):
9385

9486
class ResourceReader(metaclass=ABCMeta):
9587
@abstractmethod
96-
def open_resource(self, resource: StrOrBytesPath) -> IO[bytes]: ...
88+
def open_resource(self, resource: str) -> IO[bytes]: ...
9789
@abstractmethod
98-
def resource_path(self, resource: StrOrBytesPath) -> str: ...
90+
def resource_path(self, resource: str) -> str: ...
9991
if sys.version_info >= (3, 10):
10092
@abstractmethod
10193
def is_resource(self, path: str) -> bool: ...
@@ -115,8 +107,12 @@ if sys.version_info >= (3, 9):
115107
def is_file(self) -> bool: ...
116108
@abstractmethod
117109
def iterdir(self) -> Iterator[Traversable]: ...
118-
@abstractmethod
119-
def joinpath(self, child: StrPath) -> Traversable: ...
110+
if sys.version_info >= (3, 11):
111+
@abstractmethod
112+
def joinpath(self, *descendants: str) -> Traversable: ...
113+
else:
114+
@abstractmethod
115+
def joinpath(self, child: str) -> Traversable: ...
120116
# The .open method comes from pathlib.pyi and should be kept in sync.
121117
@overload
122118
@abstractmethod
@@ -180,7 +176,7 @@ if sys.version_info >= (3, 9):
180176
@property
181177
def name(self) -> str: ...
182178
@abstractmethod
183-
def __truediv__(self, child: StrPath) -> Traversable: ...
179+
def __truediv__(self, child: str) -> Traversable: ...
184180
@abstractmethod
185181
def read_bytes(self) -> bytes: ...
186182
@abstractmethod
@@ -189,7 +185,7 @@ if sys.version_info >= (3, 9):
189185
class TraversableResources(ResourceReader):
190186
@abstractmethod
191187
def files(self) -> Traversable: ...
192-
def open_resource(self, resource: StrPath) -> BufferedReader: ... # type: ignore[override]
188+
def open_resource(self, resource: str) -> BufferedReader: ... # type: ignore[override]
193189
def resource_path(self, resource: Any) -> NoReturn: ...
194-
def is_resource(self, path: StrPath) -> bool: ...
190+
def is_resource(self, path: str) -> bool: ...
195191
def contents(self) -> Iterator[str]: ...

mypy/typeshed/stdlib/importlib/metadata/__init__.pyi

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class _EntryPointBase(NamedTuple):
4141

4242
class EntryPoint(_EntryPointBase):
4343
pattern: ClassVar[Pattern[str]]
44+
if sys.version_info >= (3, 11):
45+
def __init__(self, name: str, value: str, group: str) -> None: ...
46+
4447
def load(self) -> Any: ... # Callable[[], Any] or an importable module
4548
@property
4649
def extras(self) -> list[str]: ...

mypy/typeshed/stdlib/inspect.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class BoundArguments:
401401
# seem to be supporting this at the moment:
402402
# _ClassTreeItem = list[_ClassTreeItem] | Tuple[type, Tuple[type, ...]]
403403
def getclasstree(classes: list[type], unique: bool = ...) -> list[Any]: ...
404-
def walktree(classes: list[type], children: dict[type[Any], list[type]], parent: type[Any] | None) -> list[Any]: ...
404+
def walktree(classes: list[type], children: Mapping[type[Any], list[type]], parent: type[Any] | None) -> list[Any]: ...
405405

406406
class Arguments(NamedTuple):
407407
args: list[str]
@@ -446,8 +446,8 @@ if sys.version_info < (3, 11):
446446
varkw: str | None = ...,
447447
defaults: tuple[Any, ...] | None = ...,
448448
kwonlyargs: Sequence[str] | None = ...,
449-
kwonlydefaults: dict[str, Any] | None = ...,
450-
annotations: dict[str, Any] = ...,
449+
kwonlydefaults: Mapping[str, Any] | None = ...,
450+
annotations: Mapping[str, Any] = ...,
451451
formatarg: Callable[[str], str] = ...,
452452
formatvarargs: Callable[[str], str] = ...,
453453
formatvarkw: Callable[[str], str] = ...,
@@ -460,7 +460,7 @@ def formatargvalues(
460460
args: list[str],
461461
varargs: str | None,
462462
varkw: str | None,
463-
locals: dict[str, Any] | None,
463+
locals: Mapping[str, Any] | None,
464464
formatarg: Callable[[str], str] | None = ...,
465465
formatvarargs: Callable[[str], str] | None = ...,
466466
formatvarkw: Callable[[str], str] | None = ...,

mypy/typeshed/stdlib/lib2to3/pgen2/grammar.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class Grammar:
1515
tokens: dict[int, int]
1616
symbol2label: dict[str, int]
1717
start: int
18-
def __init__(self) -> None: ...
1918
def dump(self, filename: StrPath) -> None: ...
2019
def load(self, filename: StrPath) -> None: ...
2120
def copy(self: Self) -> Self: ...

mypy/typeshed/stdlib/lib2to3/pgen2/pgen.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class ParserGenerator:
3232

3333
class NFAState:
3434
arcs: list[tuple[str | None, NFAState]]
35-
def __init__(self) -> None: ...
3635
def addarc(self, next: NFAState, label: str | None = ...) -> None: ...
3736

3837
class DFAState:

mypy/typeshed/stdlib/lib2to3/pgen2/tokenize.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class Untokenizer:
8787
tokens: list[str]
8888
prev_row: int
8989
prev_col: int
90-
def __init__(self) -> None: ...
9190
def add_whitespace(self, start: _Coord) -> None: ...
9291
def untokenize(self, iterable: Iterable[_TokenInfo]) -> str: ...
9392
def compat(self, token: tuple[int, str], iterable: Iterable[_TokenInfo]) -> None: ...

mypy/typeshed/stdlib/logging/__init__.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ _nameToLevel: dict[str, int]
8181

8282
class Filterer:
8383
filters: list[Filter]
84-
def __init__(self) -> None: ...
8584
def addFilter(self, filter: _FilterType) -> None: ...
8685
def removeFilter(self, filter: _FilterType) -> None: ...
8786
def filter(self, record: LogRecord) -> bool: ...

0 commit comments

Comments
 (0)