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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 9 additions & 4 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 16 additions & 17 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 2 deletions
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: ...

0 commit comments

Comments
 (0)