Skip to content

Commit

Permalink
Sync typeshed (#13831)
Browse files Browse the repository at this point in the history
Source commit:

python/typeshed@8b41b13

Reapply #13743 to remove use of `LiteralString`.

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
  • Loading branch information
cdce8p and hauntsaninja authored Oct 7, 2022
1 parent 0cab544 commit 589ad1c
Show file tree
Hide file tree
Showing 43 changed files with 133 additions and 118 deletions.
3 changes: 0 additions & 3 deletions mypy/typeshed/stdlib/_dummy_threading.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class Thread:
class _DummyThread(Thread): ...

class Lock:
def __init__(self) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
Expand All @@ -96,7 +95,6 @@ class Lock:
def locked(self) -> bool: ...

class _RLock:
def __init__(self) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
Expand Down Expand Up @@ -135,7 +133,6 @@ class Semaphore:
class BoundedSemaphore(Semaphore): ...

class Event:
def __init__(self) -> None: ...
def is_set(self) -> bool: ...
def set(self) -> None: ...
def clear(self) -> None: ...
Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/asyncio/taskgroups.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ __all__ = ["TaskGroup"]
_T = TypeVar("_T")

class TaskGroup:
def __init__(self) -> None: ...
async def __aenter__(self: Self) -> Self: ...
async def __aexit__(self, et: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ...
def create_task(
Expand Down
13 changes: 9 additions & 4 deletions mypy/typeshed/stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ __all__ = (
)

_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_T1 = TypeVar("_T1")
_T2 = TypeVar("_T2")
_T3 = TypeVar("_T3")
Expand Down Expand Up @@ -265,21 +266,25 @@ else:
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = ...) -> _T: ...

class Task(Future[_T], Generic[_T]):
# mypy and pyright complain that a subclass of an invariant class shouldn't be covariant.
# While this is true in general, here it's sort-of okay to have a covariant subclass,
# since the only reason why `asyncio.Future` is invariant is the `set_result()` method,
# and `asyncio.Task.set_result()` always raises.
class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var]
if sys.version_info >= (3, 8):
def __init__(
self,
coro: Generator[_TaskYieldType, None, _T] | Awaitable[_T],
coro: Generator[_TaskYieldType, None, _T_co] | Awaitable[_T_co],
*,
loop: AbstractEventLoop = ...,
name: str | None = ...,
) -> None: ...
else:
def __init__(
self, coro: Generator[_TaskYieldType, None, _T] | Awaitable[_T], *, loop: AbstractEventLoop = ...
self, coro: Generator[_TaskYieldType, None, _T_co] | Awaitable[_T_co], *, loop: AbstractEventLoop = ...
) -> None: ...
if sys.version_info >= (3, 8):
def get_coro(self) -> Generator[_TaskYieldType, None, _T] | Awaitable[_T]: ...
def get_coro(self) -> Generator[_TaskYieldType, None, _T_co] | Awaitable[_T_co]: ...
def get_name(self) -> str: ...
def set_name(self, __value: object) -> None: ...

Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/asyncio/unix_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ if sys.platform != "win32":

if sys.version_info >= (3, 9):
class PidfdChildWatcher(AbstractChildWatcher):
def __init__(self) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/binhex.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ LINELEN: Literal[64]
RUNCHAR: Literal[b"\x90"]

class FInfo:
def __init__(self) -> None: ...
Type: str
Creator: str
Flags: int
Expand Down
33 changes: 16 additions & 17 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1712,8 +1712,6 @@ class Exception(BaseException): ...
class StopIteration(Exception):
value: Any

_StandardError = Exception

class OSError(Exception):
errno: int
strerror: str
Expand All @@ -1728,37 +1726,38 @@ IOError = OSError
if sys.platform == "win32":
WindowsError = OSError

class ArithmeticError(_StandardError): ...
class AssertionError(_StandardError): ...
class ArithmeticError(Exception): ...
class AssertionError(Exception): ...

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

class BufferError(_StandardError): ...
class EOFError(_StandardError): ...
class BufferError(Exception): ...
class EOFError(Exception): ...

class ImportError(_StandardError):
class ImportError(Exception):
def __init__(self, *args: object, name: str | None = ..., path: str | None = ...) -> None: ...
name: str | None
path: str | None
msg: str # undocumented

class LookupError(_StandardError): ...
class MemoryError(_StandardError): ...
class LookupError(Exception): ...
class MemoryError(Exception): ...

class NameError(_StandardError):
class NameError(Exception):
if sys.version_info >= (3, 10):
name: str

class ReferenceError(_StandardError): ...
class RuntimeError(_StandardError): ...
class ReferenceError(Exception): ...
class RuntimeError(Exception): ...

class StopAsyncIteration(Exception):
value: Any

class SyntaxError(_StandardError):
class SyntaxError(Exception):
msg: str
lineno: int | None
offset: int | None
Expand All @@ -1768,9 +1767,9 @@ class SyntaxError(_StandardError):
end_lineno: int | None
end_offset: int | None

class SystemError(_StandardError): ...
class TypeError(_StandardError): ...
class ValueError(_StandardError): ...
class SystemError(Exception): ...
class TypeError(Exception): ...
class ValueError(Exception): ...
class FloatingPointError(ArithmeticError): ...
class OverflowError(ArithmeticError): ...
class ZeroDivisionError(ArithmeticError): ...
Expand Down
2 changes: 0 additions & 2 deletions mypy/typeshed/stdlib/codeop.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ def compile_command(source: str, filename: str = ..., symbol: str = ...) -> Code

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

class CommandCompiler:
compiler: Compile
def __init__(self) -> None: ...
def __call__(self, source: str, filename: str = ..., symbol: str = ...) -> CodeType | None: ...
3 changes: 0 additions & 3 deletions mypy/typeshed/stdlib/concurrent/futures/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ _T = TypeVar("_T")
_P = ParamSpec("_P")

class Future(Generic[_T]):
def __init__(self) -> None: ...
def cancel(self) -> bool: ...
def cancelled(self) -> bool: ...
def running(self) -> bool: ...
Expand Down Expand Up @@ -90,14 +89,12 @@ def wait(fs: Iterable[Future[_T]], timeout: float | None = ..., return_when: str
class _Waiter:
event: threading.Event
finished_futures: list[Future[Any]]
def __init__(self) -> None: ...
def add_result(self, future: Future[Any]) -> None: ...
def add_exception(self, future: Future[Any]) -> None: ...
def add_cancelled(self, future: Future[Any]) -> None: ...

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

class _FirstCompletedWaiter(_Waiter): ...

Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/concurrent/futures/process.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class _ThreadWakeup:
_closed: bool
_reader: Connection
_writer: Connection
def __init__(self) -> None: ...
def close(self) -> None: ...
def wakeup(self) -> None: ...
def clear(self) -> None: ...
Expand Down
2 changes: 0 additions & 2 deletions mypy/typeshed/stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ class redirect_stderr(_RedirectStream[_T_io]): ...
# In reality this is a subclass of `AbstractContextManager`;
# see #7961 for why we don't do that in the stub
class ExitStack(metaclass=abc.ABCMeta):
def __init__(self) -> None: ...
def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ...
def push(self, exit: _CM_EF) -> _CM_EF: ...
def callback(self, __callback: Callable[_P, _T], *args: _P.args, **kwds: _P.kwargs) -> Callable[_P, _T]: ...
Expand All @@ -156,7 +155,6 @@ _ACM_EF = TypeVar("_ACM_EF", bound=AbstractAsyncContextManager[Any] | _ExitCoroF
# In reality this is a subclass of `AbstractAsyncContextManager`;
# see #7961 for why we don't do that in the stub
class AsyncExitStack(metaclass=abc.ABCMeta):
def __init__(self) -> None: ...
def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ...
async def enter_async_context(self, cm: AbstractAsyncContextManager[_T]) -> _T: ...
def push(self, exit: _CM_EF) -> _CM_EF: ...
Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/csv.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,5 @@ class DictWriter(Generic[_T]):

class Sniffer:
preferred: list[str]
def __init__(self) -> None: ...
def sniff(self, sample: str, delimiters: str | None = ...) -> type[Dialect]: ...
def has_header(self, sample: str) -> bool: ...
11 changes: 9 additions & 2 deletions mypy/typeshed/stdlib/dataclasses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import types
from builtins import type as Type # alias to avoid name clashes with fields named "type"
from collections.abc import Callable, Iterable, Mapping
from typing import Any, Generic, Protocol, TypeVar, overload
from typing_extensions import Literal
from typing_extensions import Literal, TypeAlias

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

class FrozenInstanceError(AttributeError): ...

class InitVar(Generic[_T]):
if sys.version_info >= (3, 9):
_InitVarMeta: TypeAlias = type
else:
class _InitVarMeta(type):
# Not used, instead `InitVar.__class_getitem__` is called.
def __getitem__(self, params: Any) -> InitVar[Any]: ...

class InitVar(Generic[_T], metaclass=_InitVarMeta):
type: Type[_T]
def __init__(self, type: Type[_T]) -> None: ...
if sys.version_info >= (3, 9):
Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/email/contentmanager.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ from email.message import Message
from typing import Any

class ContentManager:
def __init__(self) -> None: ...
def get_content(self, msg: Message, *args: Any, **kw: Any) -> Any: ...
def set_content(self, msg: Message, obj: Any, *args: Any, **kw: Any) -> Any: ...
def add_get_handler(self, key: str, handler: Callable[..., Any]) -> None: ...
Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/formatter.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class AbstractFormatter:
def assert_line_data(self, flag: int = ...) -> None: ...

class NullWriter:
def __init__(self) -> None: ...
def flush(self) -> None: ...
def new_alignment(self, align: str | None) -> None: ...
def new_font(self, font: _FontType) -> None: ...
Expand Down
28 changes: 12 additions & 16 deletions mypy/typeshed/stdlib/importlib/abc.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import sys
import types
from _typeshed import (
OpenBinaryMode,
OpenBinaryModeReading,
OpenBinaryModeUpdating,
OpenBinaryModeWriting,
OpenTextMode,
StrOrBytesPath,
StrPath,
)
from _typeshed import OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode
from abc import ABCMeta, abstractmethod
from collections.abc import Iterator, Mapping, Sequence
from importlib.machinery import ModuleSpec
Expand Down Expand Up @@ -93,9 +85,9 @@ class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta):

class ResourceReader(metaclass=ABCMeta):
@abstractmethod
def open_resource(self, resource: StrOrBytesPath) -> IO[bytes]: ...
def open_resource(self, resource: str) -> IO[bytes]: ...
@abstractmethod
def resource_path(self, resource: StrOrBytesPath) -> str: ...
def resource_path(self, resource: str) -> str: ...
if sys.version_info >= (3, 10):
@abstractmethod
def is_resource(self, path: str) -> bool: ...
Expand All @@ -115,8 +107,12 @@ if sys.version_info >= (3, 9):
def is_file(self) -> bool: ...
@abstractmethod
def iterdir(self) -> Iterator[Traversable]: ...
@abstractmethod
def joinpath(self, child: StrPath) -> Traversable: ...
if sys.version_info >= (3, 11):
@abstractmethod
def joinpath(self, *descendants: str) -> Traversable: ...
else:
@abstractmethod
def joinpath(self, child: str) -> Traversable: ...
# The .open method comes from pathlib.pyi and should be kept in sync.
@overload
@abstractmethod
Expand Down Expand Up @@ -180,7 +176,7 @@ if sys.version_info >= (3, 9):
@property
def name(self) -> str: ...
@abstractmethod
def __truediv__(self, child: StrPath) -> Traversable: ...
def __truediv__(self, child: str) -> Traversable: ...
@abstractmethod
def read_bytes(self) -> bytes: ...
@abstractmethod
Expand All @@ -189,7 +185,7 @@ if sys.version_info >= (3, 9):
class TraversableResources(ResourceReader):
@abstractmethod
def files(self) -> Traversable: ...
def open_resource(self, resource: StrPath) -> BufferedReader: ... # type: ignore[override]
def open_resource(self, resource: str) -> BufferedReader: ... # type: ignore[override]
def resource_path(self, resource: Any) -> NoReturn: ...
def is_resource(self, path: StrPath) -> bool: ...
def is_resource(self, path: str) -> bool: ...
def contents(self) -> Iterator[str]: ...
3 changes: 3 additions & 0 deletions mypy/typeshed/stdlib/importlib/metadata/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class _EntryPointBase(NamedTuple):

class EntryPoint(_EntryPointBase):
pattern: ClassVar[Pattern[str]]
if sys.version_info >= (3, 11):
def __init__(self, name: str, value: str, group: str) -> None: ...

def load(self) -> Any: ... # Callable[[], Any] or an importable module
@property
def extras(self) -> list[str]: ...
Expand Down
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/inspect.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class BoundArguments:
# seem to be supporting this at the moment:
# _ClassTreeItem = list[_ClassTreeItem] | Tuple[type, Tuple[type, ...]]
def getclasstree(classes: list[type], unique: bool = ...) -> list[Any]: ...
def walktree(classes: list[type], children: dict[type[Any], list[type]], parent: type[Any] | None) -> list[Any]: ...
def walktree(classes: list[type], children: Mapping[type[Any], list[type]], parent: type[Any] | None) -> list[Any]: ...

class Arguments(NamedTuple):
args: list[str]
Expand Down Expand Up @@ -446,8 +446,8 @@ if sys.version_info < (3, 11):
varkw: str | None = ...,
defaults: tuple[Any, ...] | None = ...,
kwonlyargs: Sequence[str] | None = ...,
kwonlydefaults: dict[str, Any] | None = ...,
annotations: dict[str, Any] = ...,
kwonlydefaults: Mapping[str, Any] | None = ...,
annotations: Mapping[str, Any] = ...,
formatarg: Callable[[str], str] = ...,
formatvarargs: Callable[[str], str] = ...,
formatvarkw: Callable[[str], str] = ...,
Expand All @@ -460,7 +460,7 @@ def formatargvalues(
args: list[str],
varargs: str | None,
varkw: str | None,
locals: dict[str, Any] | None,
locals: Mapping[str, Any] | None,
formatarg: Callable[[str], str] | None = ...,
formatvarargs: Callable[[str], str] | None = ...,
formatvarkw: Callable[[str], str] | None = ...,
Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/lib2to3/pgen2/grammar.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Grammar:
tokens: dict[int, int]
symbol2label: dict[str, int]
start: int
def __init__(self) -> None: ...
def dump(self, filename: StrPath) -> None: ...
def load(self, filename: StrPath) -> None: ...
def copy(self: Self) -> Self: ...
Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/lib2to3/pgen2/pgen.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ParserGenerator:

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

class DFAState:
Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/lib2to3/pgen2/tokenize.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class Untokenizer:
tokens: list[str]
prev_row: int
prev_col: int
def __init__(self) -> None: ...
def add_whitespace(self, start: _Coord) -> None: ...
def untokenize(self, iterable: Iterable[_TokenInfo]) -> str: ...
def compat(self, token: tuple[int, str], iterable: Iterable[_TokenInfo]) -> None: ...
Expand Down
1 change: 0 additions & 1 deletion mypy/typeshed/stdlib/logging/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ _nameToLevel: dict[str, int]

class Filterer:
filters: list[Filter]
def __init__(self) -> None: ...
def addFilter(self, filter: _FilterType) -> None: ...
def removeFilter(self, filter: _FilterType) -> None: ...
def filter(self, record: LogRecord) -> bool: ...
Expand Down
Loading

0 comments on commit 589ad1c

Please sign in to comment.