diff --git a/mypy/typeshed/stdlib/@python2/__builtin__.pyi b/mypy/typeshed/stdlib/@python2/__builtin__.pyi index 8f42584aaa2a..ed42c1e8f380 100644 --- a/mypy/typeshed/stdlib/@python2/__builtin__.pyi +++ b/mypy/typeshed/stdlib/@python2/__builtin__.pyi @@ -43,7 +43,6 @@ from typing import ( Union, ValuesView, overload, - runtime_checkable, ) from typing_extensions import Literal @@ -838,15 +837,6 @@ def cmp(__x: Any, __y: Any) -> int: ... _N1 = TypeVar("_N1", bool, int, float, complex) def coerce(__x: _N1, __y: _N1) -> Tuple[_N1, _N1]: ... - -# This class is to be exported as PathLike from os, -# but we define it here as _PathLike to avoid import cycle issues. -# See https://github.com/python/typeshed/pull/991#issuecomment-288160993 -_AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) -@runtime_checkable -class _PathLike(Protocol[_AnyStr_co]): - def __fspath__(self) -> _AnyStr_co: ... - def compile(source: Union[Text, mod], filename: Text, mode: Text, flags: int = ..., dont_inherit: int = ...) -> Any: ... def delattr(__obj: Any, __name: Text) -> None: ... def dir(__o: object = ...) -> List[str]: ... @@ -1017,11 +1007,7 @@ def round(number: SupportsFloat) -> float: ... def round(number: SupportsFloat, ndigits: int) -> float: ... def setattr(__obj: Any, __name: Text, __value: Any) -> None: ... def sorted( - __iterable: Iterable[_T], - *, - cmp: Callable[[_T, _T], int] = ..., - key: Optional[Callable[[_T], Any]] = ..., - reverse: bool = ..., + __iterable: Iterable[_T], *, cmp: Callable[[_T, _T], int] = ..., key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ... ) -> List[_T]: ... @overload def sum(__iterable: Iterable[_T]) -> Union[_T, int]: ... diff --git a/mypy/typeshed/stdlib/@python2/_functools.pyi b/mypy/typeshed/stdlib/@python2/_functools.pyi index 6143f2a08de7..697abb78272a 100644 --- a/mypy/typeshed/stdlib/@python2/_functools.pyi +++ b/mypy/typeshed/stdlib/@python2/_functools.pyi @@ -2,6 +2,7 @@ from typing import Any, Callable, Dict, Iterable, Optional, Tuple, TypeVar, over _T = TypeVar("_T") _S = TypeVar("_S") + @overload def reduce(function: Callable[[_T, _T], _T], sequence: Iterable[_T]) -> _T: ... @overload diff --git a/mypy/typeshed/stdlib/@python2/builtins.pyi b/mypy/typeshed/stdlib/@python2/builtins.pyi index 8f42584aaa2a..ed42c1e8f380 100644 --- a/mypy/typeshed/stdlib/@python2/builtins.pyi +++ b/mypy/typeshed/stdlib/@python2/builtins.pyi @@ -43,7 +43,6 @@ from typing import ( Union, ValuesView, overload, - runtime_checkable, ) from typing_extensions import Literal @@ -838,15 +837,6 @@ def cmp(__x: Any, __y: Any) -> int: ... _N1 = TypeVar("_N1", bool, int, float, complex) def coerce(__x: _N1, __y: _N1) -> Tuple[_N1, _N1]: ... - -# This class is to be exported as PathLike from os, -# but we define it here as _PathLike to avoid import cycle issues. -# See https://github.com/python/typeshed/pull/991#issuecomment-288160993 -_AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) -@runtime_checkable -class _PathLike(Protocol[_AnyStr_co]): - def __fspath__(self) -> _AnyStr_co: ... - def compile(source: Union[Text, mod], filename: Text, mode: Text, flags: int = ..., dont_inherit: int = ...) -> Any: ... def delattr(__obj: Any, __name: Text) -> None: ... def dir(__o: object = ...) -> List[str]: ... @@ -1017,11 +1007,7 @@ def round(number: SupportsFloat) -> float: ... def round(number: SupportsFloat, ndigits: int) -> float: ... def setattr(__obj: Any, __name: Text, __value: Any) -> None: ... def sorted( - __iterable: Iterable[_T], - *, - cmp: Callable[[_T, _T], int] = ..., - key: Optional[Callable[[_T], Any]] = ..., - reverse: bool = ..., + __iterable: Iterable[_T], *, cmp: Callable[[_T, _T], int] = ..., key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ... ) -> List[_T]: ... @overload def sum(__iterable: Iterable[_T]) -> Union[_T, int]: ... diff --git a/mypy/typeshed/stdlib/@python2/functools.pyi b/mypy/typeshed/stdlib/@python2/functools.pyi index 1231dd133829..8b82177b6f6b 100644 --- a/mypy/typeshed/stdlib/@python2/functools.pyi +++ b/mypy/typeshed/stdlib/@python2/functools.pyi @@ -5,6 +5,7 @@ _AnyCallable = Callable[..., Any] _T = TypeVar("_T") _S = TypeVar("_S") + @overload def reduce(function: Callable[[_T, _T], _T], sequence: Iterable[_T]) -> _T: ... @overload diff --git a/mypy/typeshed/stdlib/@python2/itertools.pyi b/mypy/typeshed/stdlib/@python2/itertools.pyi index 59a329f7282f..addb4104419f 100644 --- a/mypy/typeshed/stdlib/@python2/itertools.pyi +++ b/mypy/typeshed/stdlib/@python2/itertools.pyi @@ -38,6 +38,7 @@ _T3 = TypeVar("_T3") _T4 = TypeVar("_T4") _T5 = TypeVar("_T5") _T6 = TypeVar("_T6") + @overload def imap(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> Iterator[_S]: ... @overload diff --git a/mypy/typeshed/stdlib/@python2/logging/__init__.pyi b/mypy/typeshed/stdlib/@python2/logging/__init__.pyi index a683113285a1..240215528527 100644 --- a/mypy/typeshed/stdlib/@python2/logging/__init__.pyi +++ b/mypy/typeshed/stdlib/@python2/logging/__init__.pyi @@ -73,24 +73,13 @@ class Logger(Filterer): ) -> None: ... fatal = critical def log( - self, - level: int, - msg: Any, - *args: Any, - exc_info: _ExcInfoType = ..., - extra: Optional[Dict[str, Any]] = ..., - **kwargs: Any, + self, level: int, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., extra: Optional[Dict[str, Any]] = ..., **kwargs: Any ) -> None: ... def exception( self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., extra: Optional[Dict[str, Any]] = ..., **kwargs: Any ) -> None: ... def _log( - self, - level: int, - msg: Any, - args: _ArgsType, - exc_info: Optional[_ExcInfoType] = ..., - extra: Optional[Dict[str, Any]] = ..., + self, level: int, msg: Any, args: _ArgsType, exc_info: Optional[_ExcInfoType] = ..., extra: Optional[Dict[str, Any]] = ... ) -> None: ... # undocumented def filter(self, record: LogRecord) -> bool: ... def addHandler(self, hdlr: Handler) -> None: ... @@ -210,13 +199,7 @@ class LoggerAdapter: self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., extra: Optional[Dict[str, Any]] = ..., **kwargs: Any ) -> None: ... def log( - self, - level: int, - msg: Any, - *args: Any, - exc_info: _ExcInfoType = ..., - extra: Optional[Dict[str, Any]] = ..., - **kwargs: Any, + self, level: int, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., extra: Optional[Dict[str, Any]] = ..., **kwargs: Any ) -> None: ... def isEnabledFor(self, level: int) -> bool: ... diff --git a/mypy/typeshed/stdlib/@python2/os/__init__.pyi b/mypy/typeshed/stdlib/@python2/os/__init__.pyi index c43b24f2bdb7..7b32f5087495 100644 --- a/mypy/typeshed/stdlib/@python2/os/__init__.pyi +++ b/mypy/typeshed/stdlib/@python2/os/__init__.pyi @@ -153,11 +153,6 @@ if sys.platform != "win32": TMP_MAX: int # Undocumented, but used by tempfile # ----- os classes (structures) ----- -if sys.version_info >= (3, 6): - from builtins import _PathLike - - PathLike = _PathLike # See comment in builtins - class _StatVFS(NamedTuple): f_bsize: int f_frsize: int diff --git a/mypy/typeshed/stdlib/_ast.pyi b/mypy/typeshed/stdlib/_ast.pyi index 1555652902ed..fd0bc107dfaf 100644 --- a/mypy/typeshed/stdlib/_ast.pyi +++ b/mypy/typeshed/stdlib/_ast.pyi @@ -25,7 +25,8 @@ class mod(AST): ... if sys.version_info >= (3, 8): class type_ignore(AST): ... - class TypeIgnore(type_ignore): ... + class TypeIgnore(type_ignore): + tag: str class FunctionType(mod): argtypes: typing.List[expr] returns: expr diff --git a/mypy/typeshed/stdlib/_typeshed/__init__.pyi b/mypy/typeshed/stdlib/_typeshed/__init__.pyi index 039c948fb055..948d4269f575 100644 --- a/mypy/typeshed/stdlib/_typeshed/__init__.pyi +++ b/mypy/typeshed/stdlib/_typeshed/__init__.pyi @@ -104,17 +104,7 @@ OpenTextModeUpdating = Literal[ "t+x", "+tx", ] -OpenTextModeWriting = Literal[ - "w", - "wt", - "tw", - "a", - "at", - "ta", - "x", - "xt", - "tx", -] +OpenTextModeWriting = Literal["w", "wt", "tw", "a", "at", "ta", "x", "xt", "tx"] OpenTextModeReading = Literal["r", "rt", "tr", "U", "rU", "Ur", "rtU", "rUt", "Urt", "trU", "tUr", "Utr"] OpenTextMode = Union[OpenTextModeUpdating, OpenTextModeWriting, OpenTextModeReading] OpenBinaryModeUpdating = Literal[ diff --git a/mypy/typeshed/stdlib/abc.pyi b/mypy/typeshed/stdlib/abc.pyi index 6be75c3bc7cc..5dd21763a9ce 100644 --- a/mypy/typeshed/stdlib/abc.pyi +++ b/mypy/typeshed/stdlib/abc.pyi @@ -7,7 +7,7 @@ _FuncT = TypeVar("_FuncT", bound=Callable[..., Any]) class ABCMeta(type): def register(cls: ABCMeta, subclass: Type[_T]) -> Type[_T]: ... -def abstractmethod(callable: _FuncT) -> _FuncT: ... +def abstractmethod(funcobj: _FuncT) -> _FuncT: ... class abstractproperty(property): ... diff --git a/mypy/typeshed/stdlib/asyncio/base_events.pyi b/mypy/typeshed/stdlib/asyncio/base_events.pyi index cdc98e69195d..90235741f40c 100644 --- a/mypy/typeshed/stdlib/asyncio/base_events.pyi +++ b/mypy/typeshed/stdlib/asyncio/base_events.pyi @@ -33,11 +33,7 @@ class Server(AbstractServer): ssl_handshake_timeout: Optional[float], ) -> None: ... else: - def __init__( - self, - loop: AbstractEventLoop, - sockets: List[socket], - ) -> None: ... + def __init__(self, loop: AbstractEventLoop, sockets: List[socket]) -> None: ... class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): def run_forever(self) -> None: ... @@ -357,7 +353,7 @@ class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): def sock_accept(self, sock: socket) -> Future[Tuple[socket, _RetAddress]]: ... # Signal handling. def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ... - def remove_signal_handler(self, sig: int) -> None: ... + def remove_signal_handler(self, sig: int) -> bool: ... # Error handlers. def set_exception_handler(self, handler: Optional[_ExceptionHandler]) -> None: ... def get_exception_handler(self) -> Optional[_ExceptionHandler]: ... diff --git a/mypy/typeshed/stdlib/asyncio/events.pyi b/mypy/typeshed/stdlib/asyncio/events.pyi index 521c69f32e12..6c9717f873cd 100644 --- a/mypy/typeshed/stdlib/asyncio/events.pyi +++ b/mypy/typeshed/stdlib/asyncio/events.pyi @@ -447,7 +447,7 @@ class AbstractEventLoop(metaclass=ABCMeta): @abstractmethod def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ... @abstractmethod - def remove_signal_handler(self, sig: int) -> None: ... + def remove_signal_handler(self, sig: int) -> bool: ... # Error handlers. @abstractmethod def set_exception_handler(self, handler: Optional[_ExceptionHandler]) -> None: ... diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index e88d9d8d27ae..de4813a5d961 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -57,16 +57,12 @@ from typing import ( Union, ValuesView, overload, - runtime_checkable, ) -from typing_extensions import Literal +from typing_extensions import Literal, SupportsIndex if sys.version_info >= (3, 9): from types import GenericAlias -class _SupportsIndex(Protocol): - def __index__(self) -> int: ... - class _SupportsTrunc(Protocol): def __trunc__(self) -> int: ... @@ -170,7 +166,7 @@ class super(object): class int: @overload - def __new__(cls: Type[_T], x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc] = ...) -> _T: ... + def __new__(cls: Type[_T], x: Union[str, bytes, SupportsInt, SupportsIndex, _SupportsTrunc] = ...) -> _T: ... @overload def __new__(cls: Type[_T], x: Union[str, bytes, bytearray], base: int) -> _T: ... if sys.version_info >= (3, 8): @@ -242,7 +238,7 @@ class int: def __index__(self) -> int: ... class float: - def __new__(cls: Type[_T], x: Union[SupportsFloat, _SupportsIndex, str, bytes, bytearray] = ...) -> _T: ... + def __new__(cls: Type[_T], x: Union[SupportsFloat, SupportsIndex, str, bytes, bytearray] = ...) -> _T: ... def as_integer_ratio(self) -> Tuple[int, int]: ... def hex(self) -> str: ... def is_integer(self) -> bool: ... @@ -299,7 +295,7 @@ class complex: @overload def __new__(cls: Type[_T], real: float = ..., imag: float = ...) -> _T: ... @overload - def __new__(cls: Type[_T], real: Union[str, SupportsComplex, _SupportsIndex]) -> _T: ... + def __new__(cls: Type[_T], real: Union[str, SupportsComplex, SupportsIndex]) -> _T: ... @property def real(self) -> float: ... @property @@ -335,19 +331,16 @@ class str(Sequence[str]): def capitalize(self) -> str: ... def casefold(self) -> str: ... def center(self, __width: int, __fillchar: str = ...) -> str: ... - def count(self, x: str, __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ...) -> int: ... + def count(self, x: str, __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...) -> int: ... def encode(self, encoding: str = ..., errors: str = ...) -> bytes: ... def endswith( - self, - __suffix: Union[str, Tuple[str, ...]], - __start: Optional[_SupportsIndex] = ..., - __end: Optional[_SupportsIndex] = ..., + self, __suffix: Union[str, Tuple[str, ...]], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ... ) -> bool: ... def expandtabs(self, tabsize: int = ...) -> str: ... - def find(self, __sub: str, __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ...) -> int: ... + def find(self, __sub: str, __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...) -> int: ... def format(self, *args: object, **kwargs: object) -> str: ... def format_map(self, map: _FormatMapMapping) -> str: ... - def index(self, __sub: str, __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ...) -> int: ... + def index(self, __sub: str, __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... if sys.version_info >= (3, 7): @@ -370,8 +363,8 @@ class str(Sequence[str]): if sys.version_info >= (3, 9): def removeprefix(self, __prefix: str) -> str: ... def removesuffix(self, __suffix: str) -> str: ... - def rfind(self, __sub: str, __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ...) -> int: ... - def rindex(self, __sub: str, __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ...) -> int: ... + def rfind(self, __sub: str, __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...) -> int: ... + def rindex(self, __sub: str, __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ...) -> int: ... def rjust(self, __width: int, __fillchar: str = ...) -> str: ... def rpartition(self, __sep: str) -> Tuple[str, str, str]: ... def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... @@ -379,10 +372,7 @@ class str(Sequence[str]): def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... def splitlines(self, keepends: bool = ...) -> List[str]: ... def startswith( - self, - __prefix: Union[str, Tuple[str, ...]], - __start: Optional[_SupportsIndex] = ..., - __end: Optional[_SupportsIndex] = ..., + self, __prefix: Union[str, Tuple[str, ...]], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ... ) -> bool: ... def strip(self, __chars: Optional[str] = ...) -> str: ... def swapcase(self) -> str: ... @@ -430,25 +420,25 @@ class bytes(ByteString): def capitalize(self) -> bytes: ... def center(self, __width: int, __fillchar: bytes = ...) -> bytes: ... def count( - self, __sub: Union[bytes, int], __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ... + self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ... ) -> int: ... def decode(self, encoding: str = ..., errors: str = ...) -> str: ... def endswith( self, __suffix: Union[bytes, Tuple[bytes, ...]], - __start: Optional[_SupportsIndex] = ..., - __end: Optional[_SupportsIndex] = ..., + __start: Optional[SupportsIndex] = ..., + __end: Optional[SupportsIndex] = ..., ) -> bool: ... def expandtabs(self, tabsize: int = ...) -> bytes: ... def find( - self, __sub: Union[bytes, int], __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ... + self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ... ) -> int: ... if sys.version_info >= (3, 8): def hex(self, sep: Union[str, bytes] = ..., bytes_per_sep: int = ...) -> str: ... else: def hex(self) -> str: ... def index( - self, __sub: Union[bytes, int], __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ... + self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ... ) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... @@ -469,10 +459,10 @@ class bytes(ByteString): def removeprefix(self, __prefix: bytes) -> bytes: ... def removesuffix(self, __suffix: bytes) -> bytes: ... def rfind( - self, __sub: Union[bytes, int], __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ... + self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ... ) -> int: ... def rindex( - self, __sub: Union[bytes, int], __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ... + self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ... ) -> int: ... def rjust(self, __width: int, __fillchar: bytes = ...) -> bytes: ... def rpartition(self, __sep: bytes) -> Tuple[bytes, bytes, bytes]: ... @@ -483,8 +473,8 @@ class bytes(ByteString): def startswith( self, __prefix: Union[bytes, Tuple[bytes, ...]], - __start: Optional[_SupportsIndex] = ..., - __end: Optional[_SupportsIndex] = ..., + __start: Optional[SupportsIndex] = ..., + __end: Optional[SupportsIndex] = ..., ) -> bool: ... def strip(self, __bytes: Optional[bytes] = ...) -> bytes: ... def swapcase(self) -> bytes: ... @@ -532,27 +522,27 @@ class bytearray(MutableSequence[int], ByteString): def capitalize(self) -> bytearray: ... def center(self, __width: int, __fillchar: bytes = ...) -> bytearray: ... def count( - self, __sub: Union[bytes, int], __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ... + self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ... ) -> int: ... def copy(self) -> bytearray: ... def decode(self, encoding: str = ..., errors: str = ...) -> str: ... def endswith( self, __suffix: Union[bytes, Tuple[bytes, ...]], - __start: Optional[_SupportsIndex] = ..., - __end: Optional[_SupportsIndex] = ..., + __start: Optional[SupportsIndex] = ..., + __end: Optional[SupportsIndex] = ..., ) -> bool: ... def expandtabs(self, tabsize: int = ...) -> bytearray: ... def extend(self, __iterable_of_ints: Iterable[int]) -> None: ... def find( - self, __sub: Union[bytes, int], __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ... + self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ... ) -> int: ... if sys.version_info >= (3, 8): def hex(self, sep: Union[str, bytes] = ..., bytes_per_sep: int = ...) -> str: ... else: def hex(self) -> str: ... def index( - self, __sub: Union[bytes, int], __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ... + self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ... ) -> int: ... def insert(self, __index: int, __item: int) -> None: ... def isalnum(self) -> bool: ... @@ -574,10 +564,10 @@ class bytearray(MutableSequence[int], ByteString): def removesuffix(self, __suffix: bytes) -> bytearray: ... def replace(self, __old: bytes, __new: bytes, __count: int = ...) -> bytearray: ... def rfind( - self, __sub: Union[bytes, int], __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ... + self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ... ) -> int: ... def rindex( - self, __sub: Union[bytes, int], __start: Optional[_SupportsIndex] = ..., __end: Optional[_SupportsIndex] = ... + self, __sub: Union[bytes, int], __start: Optional[SupportsIndex] = ..., __end: Optional[SupportsIndex] = ... ) -> int: ... def rjust(self, __width: int, __fillchar: bytes = ...) -> bytearray: ... def rpartition(self, __sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... @@ -588,8 +578,8 @@ class bytearray(MutableSequence[int], ByteString): def startswith( self, __prefix: Union[bytes, Tuple[bytes, ...]], - __start: Optional[_SupportsIndex] = ..., - __end: Optional[_SupportsIndex] = ..., + __start: Optional[SupportsIndex] = ..., + __end: Optional[SupportsIndex] = ..., ) -> bool: ... def strip(self, __bytes: Optional[bytes] = ...) -> bytearray: ... def swapcase(self) -> bytearray: ... @@ -769,14 +759,14 @@ class list(MutableSequence[_T], Generic[_T]): def __str__(self) -> str: ... __hash__: None # type: ignore @overload - def __getitem__(self, i: _SupportsIndex) -> _T: ... + def __getitem__(self, i: SupportsIndex) -> _T: ... @overload def __getitem__(self, s: slice) -> List[_T]: ... @overload - def __setitem__(self, i: _SupportsIndex, o: _T) -> None: ... + def __setitem__(self, i: SupportsIndex, o: _T) -> None: ... @overload def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... - def __delitem__(self, i: Union[_SupportsIndex, slice]) -> None: ... + def __delitem__(self, i: Union[SupportsIndex, slice]) -> None: ... def __add__(self, x: List[_T]) -> List[_T]: ... def __iadd__(self: _S, x: Iterable[_T]) -> _S: ... def __mul__(self, n: int) -> List[_T]: ... @@ -910,16 +900,16 @@ class range(Sequence[int]): stop: int step: int @overload - def __init__(self, stop: _SupportsIndex) -> None: ... + def __init__(self, stop: SupportsIndex) -> None: ... @overload - def __init__(self, start: _SupportsIndex, stop: _SupportsIndex, step: _SupportsIndex = ...) -> None: ... + def __init__(self, start: SupportsIndex, stop: SupportsIndex, step: SupportsIndex = ...) -> None: ... def count(self, value: int) -> int: ... def index(self, value: int) -> int: ... # type: ignore def __len__(self) -> int: ... def __contains__(self, o: object) -> bool: ... def __iter__(self) -> Iterator[int]: ... @overload - def __getitem__(self, i: _SupportsIndex) -> int: ... + def __getitem__(self, i: SupportsIndex) -> int: ... @overload def __getitem__(self, s: slice) -> range: ... def __repr__(self) -> str: ... @@ -954,7 +944,7 @@ def abs(__x: SupportsAbs[_T]) -> _T: ... def all(__iterable: Iterable[object]) -> bool: ... def any(__iterable: Iterable[object]) -> bool: ... def ascii(__obj: object) -> str: ... -def bin(__number: Union[int, _SupportsIndex]) -> str: ... +def bin(__number: Union[int, SupportsIndex]) -> str: ... if sys.version_info >= (3, 7): def breakpoint(*args: Any, **kws: Any) -> None: ... @@ -962,11 +952,10 @@ if sys.version_info >= (3, 7): def callable(__obj: object) -> bool: ... def chr(__i: int) -> str: ... -# This class is to be exported as PathLike from os, -# but we define it here as _PathLike to avoid import cycle issues. +# We define this here instead of using os.PathLike to avoid import cycle issues. # See https://github.com/python/typeshed/pull/991#issuecomment-288160993 _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) -@runtime_checkable + class _PathLike(Protocol[_AnyStr_co]): def __fspath__(self) -> _AnyStr_co: ... @@ -1004,9 +993,7 @@ def eval( __source: Union[str, bytes, CodeType], __globals: Optional[Dict[str, Any]] = ..., __locals: Optional[Mapping[str, Any]] = ... ) -> Any: ... def exec( - __source: Union[str, bytes, CodeType], - __globals: Optional[Dict[str, Any]] = ..., - __locals: Optional[Mapping[str, Any]] = ..., + __source: Union[str, bytes, CodeType], __globals: Optional[Dict[str, Any]] = ..., __locals: Optional[Mapping[str, Any]] = ... ) -> Any: ... def exit(code: object = ...) -> NoReturn: ... @@ -1024,7 +1011,7 @@ def globals() -> Dict[str, Any]: ... def hasattr(__obj: Any, __name: str) -> bool: ... def hash(__obj: object) -> int: ... def help(*args: Any, **kwds: Any) -> None: ... -def hex(__number: Union[int, _SupportsIndex]) -> str: ... +def hex(__number: Union[int, SupportsIndex]) -> str: ... def id(__obj: object) -> int: ... def input(__prompt: Any = ...) -> str: ... @overload @@ -1114,7 +1101,7 @@ def min(__iterable: Iterable[_T1], *, key: Callable[[_T1], SupportsLessThanT], d def next(__i: Iterator[_T]) -> _T: ... @overload def next(__i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... -def oct(__number: Union[int, _SupportsIndex]) -> str: ... +def oct(__number: Union[int, SupportsIndex]) -> str: ... _OpenFile = Union[AnyPath, int] _Opener = Callable[[str, int], int] diff --git a/mypy/typeshed/stdlib/cProfile.pyi b/mypy/typeshed/stdlib/cProfile.pyi index e5399beac9c4..638a2a79f2e5 100644 --- a/mypy/typeshed/stdlib/cProfile.pyi +++ b/mypy/typeshed/stdlib/cProfile.pyi @@ -1,6 +1,7 @@ import sys from _typeshed import AnyPath -from typing import Any, Callable, Dict, Optional, TypeVar, Union +from types import CodeType +from typing import Any, Callable, Dict, Optional, Tuple, TypeVar, Union def run(statement: str, filename: Optional[str] = ..., sort: Union[str, int] = ...) -> None: ... def runctx( @@ -9,8 +10,10 @@ def runctx( _SelfT = TypeVar("_SelfT", bound=Profile) _T = TypeVar("_T") +_Label = Tuple[str, int, str] class Profile: + stats: dict[_Label, tuple[int, int, int, int, dict[_Label, tuple[int, int, int, int]]]] # undocumented def __init__( self, timer: Callable[[], float] = ..., timeunit: float = ..., subcalls: bool = ..., builtins: bool = ... ) -> None: ... @@ -26,3 +29,5 @@ class Profile: if sys.version_info >= (3, 8): def __enter__(self: _SelfT) -> _SelfT: ... def __exit__(self, *exc_info: Any) -> None: ... + +def label(code: Union[str, CodeType]) -> _Label: ... # undocumented diff --git a/mypy/typeshed/stdlib/codecs.pyi b/mypy/typeshed/stdlib/codecs.pyi index ad4f74357558..79be8e254c4c 100644 --- a/mypy/typeshed/stdlib/codecs.pyi +++ b/mypy/typeshed/stdlib/codecs.pyi @@ -69,6 +69,7 @@ _BytesToBytesEncodingT = Literal[ "zlib", "zlib_codec", ] + @overload def encode(obj: bytes, encoding: _BytesToBytesEncodingT, errors: str = ...) -> bytes: ... @overload diff --git a/mypy/typeshed/stdlib/collections/__init__.pyi b/mypy/typeshed/stdlib/collections/__init__.pyi index 76ec87661dc9..635d32ebd294 100644 --- a/mypy/typeshed/stdlib/collections/__init__.pyi +++ b/mypy/typeshed/stdlib/collections/__init__.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, Dict, Generic, List, Optional, Tuple, Type, TypeVar, Union, overload +from typing import Any, Dict, Generic, List, NoReturn, Optional, Tuple, Type, TypeVar, Union, overload if sys.version_info >= (3, 10): from typing import ( @@ -190,7 +190,6 @@ class deque(MutableSequence[_T], Generic[_T]): def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... def __str__(self) -> str: ... - def __hash__(self) -> int: ... # These methods of deque don't really take slices, but we need to # define them as taking a slice to satisfy MutableSequence. @overload @@ -222,6 +221,8 @@ class Counter(Dict[_T, int], Generic[_T]): def copy(self: _S) -> _S: ... def elements(self) -> Iterator[_T]: ... def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ... + @classmethod + def fromkeys(cls, iterable: Any, v: Optional[int] = ...) -> NoReturn: ... # type: ignore @overload def subtract(self, __iterable: None = ...) -> None: ... @overload @@ -291,10 +292,9 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): def copy(self: _S) -> _S: ... class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]): + maps: List[Mapping[_KT, _VT]] def __init__(self, *maps: Mapping[_KT, _VT]) -> None: ... - @property - def maps(self) -> List[Mapping[_KT, _VT]]: ... - def new_child(self, m: Mapping[_KT, _VT] = ...) -> ChainMap[_KT, _VT]: ... + def new_child(self, m: Optional[Mapping[_KT, _VT]] = ...) -> ChainMap[_KT, _VT]: ... @property def parents(self) -> ChainMap[_KT, _VT]: ... def __setitem__(self, k: _KT, v: _VT) -> None: ... diff --git a/mypy/typeshed/stdlib/dataclasses.pyi b/mypy/typeshed/stdlib/dataclasses.pyi index 3fa15d9bd388..1e619516f1cc 100644 --- a/mypy/typeshed/stdlib/dataclasses.pyi +++ b/mypy/typeshed/stdlib/dataclasses.pyi @@ -9,6 +9,7 @@ _T = TypeVar("_T") class _MISSING_TYPE: ... MISSING: _MISSING_TYPE + @overload def asdict(obj: Any) -> Dict[str, Any]: ... @overload diff --git a/mypy/typeshed/stdlib/distutils/filelist.pyi b/mypy/typeshed/stdlib/distutils/filelist.pyi index ac7cdf8a15ce..99e26218f171 100644 --- a/mypy/typeshed/stdlib/distutils/filelist.pyi +++ b/mypy/typeshed/stdlib/distutils/filelist.pyi @@ -16,11 +16,7 @@ class FileList: def process_template_line(self, line: str) -> None: ... @overload def include_pattern( - self, - pattern: str, - anchor: Union[int, bool] = ..., - prefix: Optional[str] = ..., - is_regex: Literal[0, False] = ..., + self, pattern: str, anchor: Union[int, bool] = ..., prefix: Optional[str] = ..., is_regex: Literal[0, False] = ... ) -> bool: ... @overload def include_pattern(self, pattern: Union[str, Pattern[str]], *, is_regex: Literal[True, 1] = ...) -> bool: ... @@ -34,11 +30,7 @@ class FileList: ) -> bool: ... @overload def exclude_pattern( - self, - pattern: str, - anchor: Union[int, bool] = ..., - prefix: Optional[str] = ..., - is_regex: Literal[0, False] = ..., + self, pattern: str, anchor: Union[int, bool] = ..., prefix: Optional[str] = ..., is_regex: Literal[0, False] = ... ) -> bool: ... @overload def exclude_pattern(self, pattern: Union[str, Pattern[str]], *, is_regex: Literal[True, 1] = ...) -> bool: ... diff --git a/mypy/typeshed/stdlib/encodings/__init__.pyi b/mypy/typeshed/stdlib/encodings/__init__.pyi index fe59a914383d..951a53f1c786 100644 --- a/mypy/typeshed/stdlib/encodings/__init__.pyi +++ b/mypy/typeshed/stdlib/encodings/__init__.pyi @@ -1,7 +1,10 @@ from codecs import CodecInfo -from typing import Optional, Union +from typing import Any, Optional, Union class CodecRegistryError(LookupError, SystemError): ... def normalize_encoding(encoding: Union[str, bytes]) -> str: ... def search_function(encoding: str) -> Optional[CodecInfo]: ... + +# Needed for submodules +def __getattr__(name: str) -> Any: ... # incomplete diff --git a/mypy/typeshed/stdlib/fcntl.pyi b/mypy/typeshed/stdlib/fcntl.pyi index 42b88d020c6e..ebaa31749528 100644 --- a/mypy/typeshed/stdlib/fcntl.pyi +++ b/mypy/typeshed/stdlib/fcntl.pyi @@ -80,6 +80,7 @@ LOCK_RW: int LOCK_SH: int LOCK_UN: int LOCK_WRITE: int + @overload def fcntl(__fd: FileDescriptorLike, __cmd: int, __arg: int = ...) -> int: ... @overload @@ -87,6 +88,7 @@ def fcntl(__fd: FileDescriptorLike, __cmd: int, __arg: bytes) -> bytes: ... _ReadOnlyBuffer = bytes _WritableBuffer = Union[bytearray, memoryview, array[Any]] + @overload def ioctl(__fd: FileDescriptorLike, __request: int, __arg: int = ..., __mutate_flag: bool = ...) -> int: ... @overload diff --git a/mypy/typeshed/stdlib/fractions.pyi b/mypy/typeshed/stdlib/fractions.pyi index dd9c77ed3979..75cfa48a1cf6 100644 --- a/mypy/typeshed/stdlib/fractions.pyi +++ b/mypy/typeshed/stdlib/fractions.pyi @@ -1,10 +1,11 @@ import sys from decimal import Decimal from numbers import Integral, Rational, Real -from typing import Optional, Tuple, Union, overload +from typing import Optional, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal _ComparableNum = Union[int, float, Decimal, Real] +_T = TypeVar("_T") if sys.version_info < (3, 9): @overload @@ -19,10 +20,14 @@ if sys.version_info < (3, 9): class Fraction(Rational): @overload def __new__( - cls, numerator: Union[int, Rational] = ..., denominator: Optional[Union[int, Rational]] = ..., *, _normalize: bool = ... - ) -> Fraction: ... - @overload - def __new__(cls, __value: Union[float, Decimal, str], *, _normalize: bool = ...) -> Fraction: ... + cls: Type[_T], + numerator: Union[int, Rational] = ..., + denominator: Optional[Union[int, Rational]] = ..., + *, + _normalize: bool = ..., + ) -> _T: ... + @overload + def __new__(cls: Type[_T], __value: Union[float, Decimal, str], *, _normalize: bool = ...) -> _T: ... @classmethod def from_float(cls, f: float) -> Fraction: ... @classmethod diff --git a/mypy/typeshed/stdlib/ftplib.pyi b/mypy/typeshed/stdlib/ftplib.pyi index 0661301c0827..d3e4758aec47 100644 --- a/mypy/typeshed/stdlib/ftplib.pyi +++ b/mypy/typeshed/stdlib/ftplib.pyi @@ -157,9 +157,5 @@ def parse227(resp: str) -> Tuple[str, int]: ... # undocumented def parse229(resp: str, peer: Any) -> Tuple[str, int]: ... # undocumented def parse257(resp: str) -> str: ... # undocumented def ftpcp( - source: FTP, - sourcename: str, - target: FTP, - targetname: str = ..., - type: Literal["A", "I"] = ..., + source: FTP, sourcename: str, target: FTP, targetname: str = ..., type: Literal["A", "I"] = ... ) -> None: ... # undocumented diff --git a/mypy/typeshed/stdlib/functools.pyi b/mypy/typeshed/stdlib/functools.pyi index 32c65937b1e3..ceb6ffcb3f11 100644 --- a/mypy/typeshed/stdlib/functools.pyi +++ b/mypy/typeshed/stdlib/functools.pyi @@ -25,6 +25,7 @@ _AnyCallable = Callable[..., Any] _T = TypeVar("_T") _S = TypeVar("_S") + @overload def reduce(function: Callable[[_T, _S], _T], sequence: Iterable[_S], initial: _T) -> _T: ... @overload diff --git a/mypy/typeshed/stdlib/genericpath.pyi b/mypy/typeshed/stdlib/genericpath.pyi index 8171354d1f39..fc314f0a1658 100644 --- a/mypy/typeshed/stdlib/genericpath.pyi +++ b/mypy/typeshed/stdlib/genericpath.pyi @@ -1,5 +1,6 @@ import sys -from typing import AnyStr, Sequence, Text, Union +from _typeshed import AnyPath +from typing import AnyStr, Sequence, Text if sys.version_info >= (3, 0): def commonprefix(m: Sequence[str]) -> str: ... @@ -7,13 +8,7 @@ if sys.version_info >= (3, 0): else: def commonprefix(m: Sequence[AnyStr]) -> AnyStr: ... -if sys.version_info >= (3, 6): - from builtins import _PathLike - def exists(path: Union[AnyStr, _PathLike[AnyStr]]) -> bool: ... - -else: - def exists(path: Text) -> bool: ... - +def exists(path: AnyPath) -> bool: ... def isfile(path: Text) -> bool: ... def isdir(s: Text) -> bool: ... def getsize(filename: Text) -> int: ... diff --git a/mypy/typeshed/stdlib/gettext.pyi b/mypy/typeshed/stdlib/gettext.pyi index 74a5e56a74c6..dcbd214e04f8 100644 --- a/mypy/typeshed/stdlib/gettext.pyi +++ b/mypy/typeshed/stdlib/gettext.pyi @@ -29,6 +29,7 @@ class GNUTranslations(NullTranslations): def find(domain: str, localedir: Optional[StrPath] = ..., languages: Optional[Iterable[str]] = ..., all: bool = ...) -> Any: ... _T = TypeVar("_T") + @overload def translation( domain: str, diff --git a/mypy/typeshed/stdlib/http/cookies.pyi b/mypy/typeshed/stdlib/http/cookies.pyi index 18dfdb9aa3ce..1fc2179ecfd6 100644 --- a/mypy/typeshed/stdlib/http/cookies.pyi +++ b/mypy/typeshed/stdlib/http/cookies.pyi @@ -3,6 +3,7 @@ from typing import Any, Dict, Generic, Iterable, List, Mapping, Optional, Tuple, _DataType = Union[str, Mapping[str, Union[str, Morsel[Any]]]] _T = TypeVar("_T") + @overload def _quote(str: None) -> None: ... @overload diff --git a/mypy/typeshed/stdlib/http/server.pyi b/mypy/typeshed/stdlib/http/server.pyi index 7d61bc4d2e9d..f9a13d013167 100644 --- a/mypy/typeshed/stdlib/http/server.pyi +++ b/mypy/typeshed/stdlib/http/server.pyi @@ -1,11 +1,9 @@ import email.message import socketserver import sys +from os import PathLike from typing import Any, ClassVar, Dict, List, Mapping, Optional, Sequence, Tuple, Union -if sys.version_info >= (3, 7): - from builtins import _PathLike - class HTTPServer(socketserver.TCPServer): server_name: str server_port: int @@ -59,7 +57,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): request: bytes, client_address: Tuple[str, int], server: socketserver.BaseServer, - directory: Optional[Union[str, _PathLike[str]]] = ..., + directory: Optional[Union[str, PathLike[str]]] = ..., ) -> None: ... else: def __init__(self, request: bytes, client_address: Tuple[str, int], server: socketserver.BaseServer) -> None: ... diff --git a/mypy/typeshed/stdlib/importlib/abc.pyi b/mypy/typeshed/stdlib/importlib/abc.pyi index 8915b28591da..47f7f071a6c0 100644 --- a/mypy/typeshed/stdlib/importlib/abc.pyi +++ b/mypy/typeshed/stdlib/importlib/abc.pyi @@ -1,6 +1,6 @@ -import os import sys import types +from _typeshed import AnyPath from abc import ABCMeta, abstractmethod from typing import IO, Any, Iterator, Mapping, Optional, Sequence, Tuple, Union from typing_extensions import Literal @@ -62,12 +62,11 @@ class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta): def load_module(self, name: Optional[str] = ...) -> types.ModuleType: ... if sys.version_info >= (3, 7): - _PathLike = Union[bytes, str, os.PathLike[Any]] class ResourceReader(metaclass=ABCMeta): @abstractmethod - def open_resource(self, resource: _PathLike) -> IO[bytes]: ... + def open_resource(self, resource: AnyPath) -> IO[bytes]: ... @abstractmethod - def resource_path(self, resource: _PathLike) -> str: ... + def resource_path(self, resource: AnyPath) -> str: ... @abstractmethod def is_resource(self, name: str) -> bool: ... @abstractmethod diff --git a/mypy/typeshed/stdlib/importlib/util.pyi b/mypy/typeshed/stdlib/importlib/util.pyi index e2fdcb32cc98..e5d4ec399a22 100644 --- a/mypy/typeshed/stdlib/importlib/util.pyi +++ b/mypy/typeshed/stdlib/importlib/util.pyi @@ -16,11 +16,7 @@ def source_from_cache(path: str) -> str: ... def decode_source(source_bytes: bytes) -> str: ... def find_spec(name: str, package: Optional[str] = ...) -> Optional[importlib.machinery.ModuleSpec]: ... def spec_from_loader( - name: str, - loader: Optional[importlib.abc.Loader], - *, - origin: Optional[str] = ..., - is_package: Optional[bool] = ..., + name: str, loader: Optional[importlib.abc.Loader], *, origin: Optional[str] = ..., is_package: Optional[bool] = ... ) -> Optional[importlib.machinery.ModuleSpec]: ... def spec_from_file_location( name: str, diff --git a/mypy/typeshed/stdlib/logging/__init__.pyi b/mypy/typeshed/stdlib/logging/__init__.pyi index 59822ab3c66e..135d64a38a57 100644 --- a/mypy/typeshed/stdlib/logging/__init__.pyi +++ b/mypy/typeshed/stdlib/logging/__init__.pyi @@ -706,7 +706,7 @@ else: ) -> None: ... def shutdown(handlerList: Sequence[Any] = ...) -> None: ... # handlerList is undocumented -def setLoggerClass(klass: type) -> None: ... +def setLoggerClass(klass: Type[Logger]) -> None: ... def captureWarnings(capture: bool) -> None: ... def setLogRecordFactory(factory: Callable[..., LogRecord]) -> None: ... diff --git a/mypy/typeshed/stdlib/logging/config.pyi b/mypy/typeshed/stdlib/logging/config.pyi index 89fa555faa8f..c06f0b25291f 100644 --- a/mypy/typeshed/stdlib/logging/config.pyi +++ b/mypy/typeshed/stdlib/logging/config.pyi @@ -12,9 +12,7 @@ else: def dictConfig(config: dict[str, Any]) -> None: ... def fileConfig( - fname: Union[_Path, IO[str], RawConfigParser], - defaults: Optional[dict[str, str]] = ..., - disable_existing_loggers: bool = ..., + fname: Union[_Path, IO[str], RawConfigParser], defaults: Optional[dict[str, str]] = ..., disable_existing_loggers: bool = ... ) -> None: ... def listen(port: int = ..., verify: Optional[Callable[[bytes], Optional[bytes]]] = ...) -> Thread: ... def stopListening() -> None: ... diff --git a/mypy/typeshed/stdlib/macpath.pyi b/mypy/typeshed/stdlib/macpath.pyi index 0b5ccbf05f65..2a81776605b5 100644 --- a/mypy/typeshed/stdlib/macpath.pyi +++ b/mypy/typeshed/stdlib/macpath.pyi @@ -7,7 +7,7 @@ if sys.version_info < (3, 8): _T = TypeVar("_T") if sys.version_info >= (3, 6): - from builtins import _PathLike + from os import PathLike # ----- os.path variables ----- supports_unicode_filenames: bool @@ -25,35 +25,35 @@ if sys.version_info < (3, 8): if sys.version_info >= (3, 6): # Overloads are necessary to work around python/mypy#3644. @overload - def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... + def abspath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def abspath(path: AnyStr) -> AnyStr: ... @overload - def basename(s: _PathLike[AnyStr]) -> AnyStr: ... + def basename(s: PathLike[AnyStr]) -> AnyStr: ... @overload def basename(s: AnyStr) -> AnyStr: ... @overload - def dirname(s: _PathLike[AnyStr]) -> AnyStr: ... + def dirname(s: PathLike[AnyStr]) -> AnyStr: ... @overload def dirname(s: AnyStr) -> AnyStr: ... @overload - def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... + def expanduser(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expanduser(path: AnyStr) -> AnyStr: ... @overload - def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... + def expandvars(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expandvars(path: AnyStr) -> AnyStr: ... @overload - def normcase(path: _PathLike[AnyStr]) -> AnyStr: ... + def normcase(path: PathLike[AnyStr]) -> AnyStr: ... @overload def normcase(path: AnyStr) -> AnyStr: ... @overload - def normpath(s: _PathLike[AnyStr]) -> AnyStr: ... + def normpath(s: PathLike[AnyStr]) -> AnyStr: ... @overload def normpath(s: AnyStr) -> AnyStr: ... @overload - def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(path: AnyStr) -> AnyStr: ... else: @@ -113,15 +113,15 @@ if sys.version_info < (3, 8): def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... if sys.version_info >= (3, 6): @overload - def split(s: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + def split(s: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def split(s: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload - def splitdrive(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload - def splitext(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... else: diff --git a/mypy/typeshed/stdlib/mailbox.pyi b/mypy/typeshed/stdlib/mailbox.pyi index e22788d21517..d968e7d77244 100644 --- a/mypy/typeshed/stdlib/mailbox.pyi +++ b/mypy/typeshed/stdlib/mailbox.pyi @@ -100,20 +100,18 @@ class Maildir(Mailbox[MaildirMessage]): class _singlefileMailbox(Mailbox[_MessageT]): ... class _mboxMMDF(_singlefileMailbox[_MessageT]): - def get_file(self, key: str) -> _PartialFile[bytes]: ... + def get_file(self, key: str, from_: bool = ...) -> _PartialFile[bytes]: ... + def get_bytes(self, key: str, from_: bool = ...) -> bytes: ... + def get_string(self, key: str, from_: bool = ...) -> str: ... class mbox(_mboxMMDF[mboxMessage]): - def __init__( - self, dirname: AnyPath, factory: Optional[Callable[[IO[Any]], mboxMessage]] = ..., create: bool = ... - ) -> None: ... + def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], mboxMessage]] = ..., create: bool = ...) -> None: ... class MMDF(_mboxMMDF[MMDFMessage]): - def __init__( - self, dirname: AnyPath, factory: Optional[Callable[[IO[Any]], MMDFMessage]] = ..., create: bool = ... - ) -> None: ... + def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], MMDFMessage]] = ..., create: bool = ...) -> None: ... class MH(Mailbox[MHMessage]): - def __init__(self, dirname: AnyPath, factory: Optional[Callable[[IO[Any]], MHMessage]] = ..., create: bool = ...) -> None: ... + def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], MHMessage]] = ..., create: bool = ...) -> None: ... def get_file(self, key: str) -> _ProxyFile[bytes]: ... def list_folders(self) -> List[str]: ... def get_folder(self, folder: AnyPath) -> MH: ... @@ -124,9 +122,7 @@ class MH(Mailbox[MHMessage]): def pack(self) -> None: ... class Babyl(_singlefileMailbox[BabylMessage]): - def __init__( - self, dirname: AnyPath, factory: Optional[Callable[[IO[Any]], BabylMessage]] = ..., create: bool = ... - ) -> None: ... + def __init__(self, path: AnyPath, factory: Optional[Callable[[IO[Any]], BabylMessage]] = ..., create: bool = ...) -> None: ... def get_file(self, key: str) -> IO[bytes]: ... def get_labels(self) -> List[str]: ... diff --git a/mypy/typeshed/stdlib/mimetypes.pyi b/mypy/typeshed/stdlib/mimetypes.pyi index 43f27dda4d7b..f0cfac32cafd 100644 --- a/mypy/typeshed/stdlib/mimetypes.pyi +++ b/mypy/typeshed/stdlib/mimetypes.pyi @@ -11,7 +11,7 @@ else: def guess_all_extensions(type: str, strict: bool = ...) -> List[str]: ... def guess_extension(type: str, strict: bool = ...) -> Optional[str]: ... def init(files: Optional[Sequence[str]] = ...) -> None: ... -def read_mime_types(filename: str) -> Optional[Dict[str, str]]: ... +def read_mime_types(file: str) -> Optional[Dict[str, str]]: ... def add_type(type: str, ext: str, strict: bool = ...) -> None: ... inited: bool diff --git a/mypy/typeshed/stdlib/ntpath.pyi b/mypy/typeshed/stdlib/ntpath.pyi index 33536f751205..4ee1b31c64e3 100644 --- a/mypy/typeshed/stdlib/ntpath.pyi +++ b/mypy/typeshed/stdlib/ntpath.pyi @@ -1,8 +1,8 @@ import os import sys from _typeshed import AnyPath, BytesPath, StrPath -from builtins import _PathLike from genericpath import exists as exists +from os import PathLike from typing import Any, AnyStr, Optional, Sequence, Tuple, TypeVar, overload _T = TypeVar("_T") @@ -25,43 +25,43 @@ devnull: str # ----- os.path function stubs ----- # Overloads are necessary to work around python/mypy#3644. @overload -def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... +def abspath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def abspath(path: AnyStr) -> AnyStr: ... @overload -def basename(p: _PathLike[AnyStr]) -> AnyStr: ... +def basename(p: PathLike[AnyStr]) -> AnyStr: ... @overload def basename(p: AnyStr) -> AnyStr: ... @overload -def dirname(p: _PathLike[AnyStr]) -> AnyStr: ... +def dirname(p: PathLike[AnyStr]) -> AnyStr: ... @overload def dirname(p: AnyStr) -> AnyStr: ... @overload -def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... +def expanduser(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expanduser(path: AnyStr) -> AnyStr: ... @overload -def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... +def expandvars(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expandvars(path: AnyStr) -> AnyStr: ... @overload -def normcase(s: _PathLike[AnyStr]) -> AnyStr: ... +def normcase(s: PathLike[AnyStr]) -> AnyStr: ... @overload def normcase(s: AnyStr) -> AnyStr: ... @overload -def normpath(path: _PathLike[AnyStr]) -> AnyStr: ... +def normpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def normpath(path: AnyStr) -> AnyStr: ... if sys.platform == "win32": @overload - def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(path: AnyStr) -> AnyStr: ... else: @overload - def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(filename: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(filename: AnyStr) -> AnyStr: ... @@ -97,15 +97,15 @@ def samefile(f1: AnyPath, f2: AnyPath) -> bool: ... def sameopenfile(fp1: int, fp2: int) -> bool: ... def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... @overload -def split(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def split(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload -def splitdrive(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload -def splitext(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... diff --git a/mypy/typeshed/stdlib/os/__init__.pyi b/mypy/typeshed/stdlib/os/__init__.pyi index f88f9c6a9cc0..98f078be869f 100644 --- a/mypy/typeshed/stdlib/os/__init__.pyi +++ b/mypy/typeshed/stdlib/os/__init__.pyi @@ -8,7 +8,7 @@ from _typeshed import ( OpenBinaryModeWriting, OpenTextMode, ) -from builtins import OSError, _PathLike +from builtins import OSError from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper as _TextIOWrapper from posix import listdir as listdir, times_result from subprocess import Popen @@ -28,12 +28,14 @@ from typing import ( MutableMapping, NoReturn, Optional, + Protocol, Sequence, Set, Tuple, TypeVar, Union, overload, + runtime_checkable, ) from typing_extensions import Literal @@ -46,6 +48,7 @@ if sys.version_info >= (3, 9): _supports_unicode_filenames = path.supports_unicode_filenames _T = TypeVar("_T") +_AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) # ----- os variables ----- @@ -301,7 +304,9 @@ class stat_result: st_creator: int st_type: int -PathLike = _PathLike # See comment in builtins +@runtime_checkable +class PathLike(Protocol[_AnyStr_co]): + def __fspath__(self) -> _AnyStr_co: ... _FdOrAnyPath = Union[int, AnyPath] @@ -428,6 +433,7 @@ if sys.platform != "win32": def unsetenv(__name: Union[bytes, str]) -> None: ... _Opener = Callable[[str, int], int] + @overload def fdopen( fd: int, diff --git a/mypy/typeshed/stdlib/os/path.pyi b/mypy/typeshed/stdlib/os/path.pyi index 9fe5a7df6c85..2fcbe12f8a08 100644 --- a/mypy/typeshed/stdlib/os/path.pyi +++ b/mypy/typeshed/stdlib/os/path.pyi @@ -1,8 +1,8 @@ import os import sys from _typeshed import AnyPath, BytesPath, StrPath -from builtins import _PathLike from genericpath import exists as exists +from os import PathLike from typing import Any, AnyStr, Optional, Sequence, Tuple, TypeVar, overload _T = TypeVar("_T") @@ -25,43 +25,43 @@ devnull: str # ----- os.path function stubs ----- # Overloads are necessary to work around python/mypy#3644. @overload -def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... +def abspath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def abspath(path: AnyStr) -> AnyStr: ... @overload -def basename(p: _PathLike[AnyStr]) -> AnyStr: ... +def basename(p: PathLike[AnyStr]) -> AnyStr: ... @overload def basename(p: AnyStr) -> AnyStr: ... @overload -def dirname(p: _PathLike[AnyStr]) -> AnyStr: ... +def dirname(p: PathLike[AnyStr]) -> AnyStr: ... @overload def dirname(p: AnyStr) -> AnyStr: ... @overload -def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... +def expanduser(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expanduser(path: AnyStr) -> AnyStr: ... @overload -def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... +def expandvars(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expandvars(path: AnyStr) -> AnyStr: ... @overload -def normcase(s: _PathLike[AnyStr]) -> AnyStr: ... +def normcase(s: PathLike[AnyStr]) -> AnyStr: ... @overload def normcase(s: AnyStr) -> AnyStr: ... @overload -def normpath(path: _PathLike[AnyStr]) -> AnyStr: ... +def normpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def normpath(path: AnyStr) -> AnyStr: ... if sys.platform == "win32": @overload - def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(path: AnyStr) -> AnyStr: ... else: @overload - def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(filename: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(filename: AnyStr) -> AnyStr: ... @@ -97,15 +97,15 @@ def samefile(f1: AnyPath, f2: AnyPath) -> bool: ... def sameopenfile(fp1: int, fp2: int) -> bool: ... def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... @overload -def split(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def split(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload -def splitdrive(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload -def splitext(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... diff --git a/mypy/typeshed/stdlib/pathlib.pyi b/mypy/typeshed/stdlib/pathlib.pyi index cd00398fe74e..b4624c3bea73 100644 --- a/mypy/typeshed/stdlib/pathlib.pyi +++ b/mypy/typeshed/stdlib/pathlib.pyi @@ -1,7 +1,7 @@ -import os import sys -from _typeshed import OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode +from _typeshed import OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode, StrPath from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper +from os import PathLike, stat_result from types import TracebackType from typing import IO, Any, BinaryIO, Generator, List, Optional, Sequence, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal @@ -11,10 +11,7 @@ if sys.version_info >= (3, 9): _P = TypeVar("_P", bound=PurePath) -_PurePathBase = os.PathLike[str] -_PathLike = os.PathLike[str] - -class PurePath(_PurePathBase): +class PurePath(PathLike[str]): parts: Tuple[str, ...] drive: str root: str @@ -23,28 +20,28 @@ class PurePath(_PurePathBase): suffix: str suffixes: List[str] stem: str - def __new__(cls: Type[_P], *args: Union[str, _PathLike]) -> _P: ... + def __new__(cls: Type[_P], *args: StrPath) -> _P: ... def __hash__(self) -> int: ... def __lt__(self, other: PurePath) -> bool: ... def __le__(self, other: PurePath) -> bool: ... def __gt__(self, other: PurePath) -> bool: ... def __ge__(self, other: PurePath) -> bool: ... - def __truediv__(self: _P, key: Union[str, _PathLike]) -> _P: ... - def __rtruediv__(self: _P, key: Union[str, _PathLike]) -> _P: ... + def __truediv__(self: _P, key: StrPath) -> _P: ... + def __rtruediv__(self: _P, key: StrPath) -> _P: ... def __bytes__(self) -> bytes: ... def as_posix(self) -> str: ... def as_uri(self) -> str: ... def is_absolute(self) -> bool: ... def is_reserved(self) -> bool: ... if sys.version_info >= (3, 9): - def is_relative_to(self, *other: Union[str, os.PathLike[str]]) -> bool: ... + def is_relative_to(self, *other: StrPath) -> bool: ... def match(self, path_pattern: str) -> bool: ... - def relative_to(self: _P, *other: Union[str, _PathLike]) -> _P: ... + def relative_to(self: _P, *other: StrPath) -> _P: ... def with_name(self: _P, name: str) -> _P: ... if sys.version_info >= (3, 9): def with_stem(self: _P, stem: str) -> _P: ... def with_suffix(self: _P, suffix: str) -> _P: ... - def joinpath(self: _P, *other: Union[str, _PathLike]) -> _P: ... + def joinpath(self: _P, *other: StrPath) -> _P: ... @property def parents(self: _P) -> Sequence[_P]: ... @property @@ -56,14 +53,14 @@ class PurePosixPath(PurePath): ... class PureWindowsPath(PurePath): ... class Path(PurePath): - def __new__(cls: Type[_P], *args: Union[str, _PathLike], **kwargs: Any) -> _P: ... + def __new__(cls: Type[_P], *args: StrPath, **kwargs: Any) -> _P: ... def __enter__(self: _P) -> _P: ... def __exit__( self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], traceback: Optional[TracebackType] ) -> Optional[bool]: ... @classmethod def cwd(cls: Type[_P]) -> _P: ... - def stat(self) -> os.stat_result: ... + def stat(self) -> stat_result: ... def chmod(self, mode: int) -> None: ... def exists(self) -> bool: ... def glob(self: _P, pattern: str) -> Generator[_P, None, None]: ... @@ -79,7 +76,7 @@ class Path(PurePath): def is_char_device(self) -> bool: ... def iterdir(self: _P) -> Generator[_P, None, None]: ... def lchmod(self, mode: int) -> None: ... - def lstat(self) -> os.stat_result: ... + def lstat(self) -> stat_result: ... def mkdir(self, mode: int = ..., parents: bool = ..., exist_ok: bool = ...) -> None: ... # Adapted from builtins.open # Text mode: always returns a TextIOWrapper @@ -168,7 +165,7 @@ class Path(PurePath): def write_bytes(self, data: bytes) -> int: ... def write_text(self, data: str, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> int: ... if sys.version_info >= (3, 8): - def link_to(self, target: Union[str, bytes, os.PathLike[str]]) -> None: ... + def link_to(self, target: Union[StrPath, bytes]) -> None: ... class PosixPath(Path, PurePosixPath): ... class WindowsPath(Path, PureWindowsPath): ... diff --git a/mypy/typeshed/stdlib/posix.pyi b/mypy/typeshed/stdlib/posix.pyi index 9080d5b90245..5d0f69fa4394 100644 --- a/mypy/typeshed/stdlib/posix.pyi +++ b/mypy/typeshed/stdlib/posix.pyi @@ -1,6 +1,5 @@ import sys -from builtins import _PathLike # See comment in builtins -from os import stat_result as stat_result +from os import PathLike, stat_result as stat_result from typing import Dict, List, NamedTuple, Optional, overload class uname_result(NamedTuple): @@ -150,6 +149,7 @@ WUNTRACED: int XATTR_CREATE: int XATTR_REPLACE: int XATTR_SIZE_MAX: int + @overload def listdir(path: Optional[str] = ...) -> List[str]: ... @overload @@ -157,7 +157,7 @@ def listdir(path: bytes) -> List[bytes]: ... @overload def listdir(path: int) -> List[str]: ... @overload -def listdir(path: _PathLike[str]) -> List[str]: ... +def listdir(path: PathLike[str]) -> List[str]: ... if sys.platform == "win32": environ: Dict[str, str] diff --git a/mypy/typeshed/stdlib/posixpath.pyi b/mypy/typeshed/stdlib/posixpath.pyi index 9fe5a7df6c85..2fcbe12f8a08 100644 --- a/mypy/typeshed/stdlib/posixpath.pyi +++ b/mypy/typeshed/stdlib/posixpath.pyi @@ -1,8 +1,8 @@ import os import sys from _typeshed import AnyPath, BytesPath, StrPath -from builtins import _PathLike from genericpath import exists as exists +from os import PathLike from typing import Any, AnyStr, Optional, Sequence, Tuple, TypeVar, overload _T = TypeVar("_T") @@ -25,43 +25,43 @@ devnull: str # ----- os.path function stubs ----- # Overloads are necessary to work around python/mypy#3644. @overload -def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... +def abspath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def abspath(path: AnyStr) -> AnyStr: ... @overload -def basename(p: _PathLike[AnyStr]) -> AnyStr: ... +def basename(p: PathLike[AnyStr]) -> AnyStr: ... @overload def basename(p: AnyStr) -> AnyStr: ... @overload -def dirname(p: _PathLike[AnyStr]) -> AnyStr: ... +def dirname(p: PathLike[AnyStr]) -> AnyStr: ... @overload def dirname(p: AnyStr) -> AnyStr: ... @overload -def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... +def expanduser(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expanduser(path: AnyStr) -> AnyStr: ... @overload -def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... +def expandvars(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expandvars(path: AnyStr) -> AnyStr: ... @overload -def normcase(s: _PathLike[AnyStr]) -> AnyStr: ... +def normcase(s: PathLike[AnyStr]) -> AnyStr: ... @overload def normcase(s: AnyStr) -> AnyStr: ... @overload -def normpath(path: _PathLike[AnyStr]) -> AnyStr: ... +def normpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def normpath(path: AnyStr) -> AnyStr: ... if sys.platform == "win32": @overload - def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(path: AnyStr) -> AnyStr: ... else: @overload - def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(filename: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(filename: AnyStr) -> AnyStr: ... @@ -97,15 +97,15 @@ def samefile(f1: AnyPath, f2: AnyPath) -> bool: ... def sameopenfile(fp1: int, fp2: int) -> bool: ... def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... @overload -def split(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def split(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload -def splitdrive(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload -def splitext(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... diff --git a/mypy/typeshed/stdlib/profile.pyi b/mypy/typeshed/stdlib/profile.pyi index d5f4bd4d5271..cc769b604a71 100644 --- a/mypy/typeshed/stdlib/profile.pyi +++ b/mypy/typeshed/stdlib/profile.pyi @@ -1,5 +1,5 @@ from _typeshed import AnyPath -from typing import Any, Callable, Dict, Optional, TypeVar, Union +from typing import Any, Callable, Dict, Optional, Tuple, TypeVar, Union def run(statement: str, filename: Optional[str] = ..., sort: Union[str, int] = ...) -> None: ... def runctx( @@ -8,9 +8,11 @@ def runctx( _SelfT = TypeVar("_SelfT", bound=Profile) _T = TypeVar("_T") +_Label = Tuple[str, int, str] class Profile: bias: int + stats: dict[_Label, tuple[int, int, int, int, dict[_Label, tuple[int, int, int, int]]]] # undocumented def __init__(self, timer: Optional[Callable[[], float]] = ..., bias: Optional[int] = ...) -> None: ... def set_cmd(self, cmd: str) -> None: ... def simulate_call(self, name: str) -> None: ... diff --git a/mypy/typeshed/stdlib/smtpd.pyi b/mypy/typeshed/stdlib/smtpd.pyi index a4f9bfa6593c..92f078a063f6 100644 --- a/mypy/typeshed/stdlib/smtpd.pyi +++ b/mypy/typeshed/stdlib/smtpd.pyi @@ -87,18 +87,10 @@ class DebuggingServer(SMTPServer): ... class PureProxy(SMTPServer): def process_message( # type: ignore - self, - peer: _Address, - mailfrom: str, - rcpttos: List[Text], - data: Union[bytes, str], + self, peer: _Address, mailfrom: str, rcpttos: List[Text], data: Union[bytes, str] ) -> Optional[str]: ... class MailmanProxy(PureProxy): def process_message( # type: ignore - self, - peer: _Address, - mailfrom: str, - rcpttos: List[Text], - data: Union[bytes, str], + self, peer: _Address, mailfrom: str, rcpttos: List[Text], data: Union[bytes, str] ) -> Optional[str]: ... diff --git a/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi b/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi index 51def54066d6..0eaab5eff2a9 100644 --- a/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi +++ b/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi @@ -1,7 +1,7 @@ import os import sys from datetime import date, datetime, time -from typing import Any, Callable, Generator, Iterable, Iterator, List, Optional, Text, Tuple, Type, TypeVar, Union +from typing import Any, Callable, Generator, Iterable, Iterator, List, Optional, Protocol, Text, Tuple, Type, TypeVar, Union _T = TypeVar("_T") @@ -113,6 +113,10 @@ if sys.version_info < (3, 8): def display(self, *args, **kwargs) -> None: ... def get(self, *args, **kwargs) -> None: ... +class _AggregateProtocol(Protocol): + def step(self, value: int) -> None: ... + def finalize(self) -> int: ... + class Connection(object): DataError: Any DatabaseError: Any @@ -132,7 +136,7 @@ class Connection(object): def __init__(self, *args: Any, **kwargs: Any) -> None: ... def close(self) -> None: ... def commit(self) -> None: ... - def create_aggregate(self, name: str, num_params: int, aggregate_class: type) -> None: ... + def create_aggregate(self, name: str, num_params: int, aggregate_class: Callable[[], _AggregateProtocol]) -> None: ... def create_collation(self, name: str, callable: Any) -> None: ... if sys.version_info >= (3, 8): def create_function(self, name: str, num_params: int, func: Any, *, deterministic: bool = ...) -> None: ... diff --git a/mypy/typeshed/stdlib/telnetlib.pyi b/mypy/typeshed/stdlib/telnetlib.pyi index 1f5be7a73c98..31fd3eef81cd 100644 --- a/mypy/typeshed/stdlib/telnetlib.pyi +++ b/mypy/typeshed/stdlib/telnetlib.pyi @@ -83,15 +83,15 @@ NOOPT: bytes class Telnet: host: Optional[str] # undocumented - def __init__(self, host: Optional[str] = ..., port: int = ..., timeout: int = ...) -> None: ... - def open(self, host: str, port: int = ..., timeout: int = ...) -> None: ... + def __init__(self, host: Optional[str] = ..., port: int = ..., timeout: float = ...) -> None: ... + def open(self, host: str, port: int = ..., timeout: float = ...) -> None: ... def msg(self, msg: str, *args: Any) -> None: ... def set_debuglevel(self, debuglevel: int) -> None: ... def close(self) -> None: ... def get_socket(self) -> socket.socket: ... def fileno(self) -> int: ... def write(self, buffer: bytes) -> None: ... - def read_until(self, match: bytes, timeout: Optional[int] = ...) -> bytes: ... + def read_until(self, match: bytes, timeout: Optional[float] = ...) -> bytes: ... def read_all(self) -> bytes: ... def read_some(self) -> bytes: ... def read_very_eager(self) -> bytes: ... @@ -108,7 +108,7 @@ class Telnet: def mt_interact(self) -> None: ... def listener(self) -> None: ... def expect( - self, list: Sequence[Union[Pattern[bytes], bytes]], timeout: Optional[int] = ... + self, list: Sequence[Union[Pattern[bytes], bytes]], timeout: Optional[float] = ... ) -> Tuple[int, Optional[Match[bytes]], bytes]: ... if sys.version_info >= (3, 6): def __enter__(self) -> Telnet: ... diff --git a/mypy/typeshed/stdlib/tkinter/__init__.pyi b/mypy/typeshed/stdlib/tkinter/__init__.pyi index 56e8d60b9779..3597344dd965 100644 --- a/mypy/typeshed/stdlib/tkinter/__init__.pyi +++ b/mypy/typeshed/stdlib/tkinter/__init__.pyi @@ -105,6 +105,7 @@ _TkinterSequence2D = Union[List[List[_T]], List[Tuple[_T, ...]], Tuple[List[_T], _Anchor = Literal["nw", "n", "ne", "w", "center", "e", "sw", "s", "se"] # manual page: Tk_GetAnchor _Bitmap = str # manual page: Tk_GetBitmap _ButtonCommand = Union[str, Callable[[], Any]] # return value is returned from Button.invoke() +_CanvasItemId = int # handles for items created on a canvas - can be passed to Canvas.delete() _Color = str # typically '#rrggbb', '#rgb' or color names. _Compound = Literal["top", "left", "center", "right", "bottom", "none"] # -compound in manual page named 'options' _Cursor = Union[str, Tuple[str], Tuple[str, str], Tuple[str, str, str], Tuple[str, str, str, str]] # manual page: Tk_GetCursor @@ -347,10 +348,7 @@ class Misc: # binds do. The default value of func is not str. @overload def bind( - self, - sequence: Optional[str] = ..., - func: Optional[Callable[[Event[Misc]], Any]] = ..., - add: Optional[bool] = ..., + self, sequence: Optional[str] = ..., func: Optional[Callable[[Event[Misc]], Any]] = ..., add: Optional[bool] = ... ) -> str: ... @overload def bind(self, sequence: Optional[str], func: str, add: Optional[bool] = ...) -> None: ... @@ -360,10 +358,7 @@ class Misc: # callbacks will get, so those are Misc. @overload def bind_all( - self, - sequence: Optional[str] = ..., - func: Optional[Callable[[Event[Misc]], Any]] = ..., - add: Optional[bool] = ..., + self, sequence: Optional[str] = ..., func: Optional[Callable[[Event[Misc]], Any]] = ..., add: Optional[bool] = ... ) -> str: ... @overload def bind_all(self, sequence: Optional[str], func: str, add: Optional[bool] = ...) -> None: ... @@ -839,10 +834,7 @@ class Widget(BaseWidget, Pack, Place, Grid): # widgets don't. @overload def bind( - self: _W, - sequence: Optional[str] = ..., - func: Optional[Callable[[Event[_W]], Any]] = ..., - add: Optional[bool] = ..., + self: _W, sequence: Optional[str] = ..., func: Optional[Callable[[Event[_W]], Any]] = ..., add: Optional[bool] = ... ) -> str: ... @overload def bind(self, sequence: Optional[str], func: str, add: Optional[bool] = ...) -> None: ... @@ -948,7 +940,7 @@ class Button(Widget): repeatinterval: int = ..., state: Literal["normal", "active", "disabled"] = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., # We allow the textvariable to be any Variable, not necessarly # StringVar. This is useful for e.g. a button that displays the value # of an IntVar. @@ -993,7 +985,7 @@ class Button(Widget): repeatinterval: int = ..., state: Literal["normal", "active", "disabled"] = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: Variable = ..., underline: int = ..., width: _ScreenUnits = ..., @@ -1112,26 +1104,178 @@ class Canvas(Widget, XView, YView): def canvasx(self, screenx, gridspacing: Optional[Any] = ...): ... def canvasy(self, screeny, gridspacing: Optional[Any] = ...): ... def coords(self, *args): ... - def create_arc(self, *args, **kw): ... - def create_bitmap(self, *args, **kw): ... - def create_image(self, *args, **kw): ... - def create_line(self, *args, **kw): ... - def create_oval(self, *args, **kw): ... - def create_polygon(self, *args, **kw): ... - def create_rectangle(self, *args, **kw): ... - def create_text(self, *args, **kw): ... - def create_window(self, *args, **kw): ... + def create_arc(self, *args, **kw) -> _CanvasItemId: ... + def create_bitmap(self, *args, **kw) -> _CanvasItemId: ... + def create_image(self, *args, **kw) -> _CanvasItemId: ... + def create_line( + self, + __x0: float, + __y0: float, + __x1: float, + __y1: float, + *, + activedash: _Color = ..., + activefill: _Color = ..., + activestipple: str = ..., + activewidth: _ScreenUnits = ..., + arrow: Literal["first", "last", "both"] = ..., + arrowshape: Tuple[float, float, float] = ..., + capstyle: Literal["round", "projecting", "butt"] = ..., + dash: Union[Tuple[float], Tuple[float, float], Tuple[float, float, float, float]] = ..., + dashoffset: _ScreenUnits = ..., + disableddash: _Color = ..., + disabledfill: _Color = ..., + disabledstipple: _Bitmap = ..., + disabledwidth: _ScreenUnits = ..., + fill: _Color = ..., + joinstyle: Literal["round", "bevel", "miter"] = ..., + offset: _ScreenUnits = ..., + smooth: bool = ..., + splinesteps: float = ..., + state: Literal["normal", "active", "disabled"] = ..., + stipple: _Bitmap = ..., + tags: Union[str, Tuple[str, ...]] = ..., + width: _ScreenUnits = ..., + ) -> _CanvasItemId: ... + def create_oval( + self, + __x0: float, + __y0: float, + __x1: float, + __y1: float, + *, + activedash: _Color = ..., + activefill: _Color = ..., + activeoutline: _Color = ..., + activeoutlinestipple: _Color = ..., + activestipple: str = ..., + activewidth: _ScreenUnits = ..., + dash: Union[Tuple[float], Tuple[float, float], Tuple[float, float, float, float]] = ..., + dashoffset: _ScreenUnits = ..., + disableddash: _Color = ..., + disabledfill: _Color = ..., + disabledoutline: _Color = ..., + disabledoutlinestipple: _Color = ..., + disabledstipple: _Bitmap = ..., + disabledwidth: _ScreenUnits = ..., + fill: _Color = ..., + offset: _ScreenUnits = ..., + outline: _Color = ..., + outlineoffset: _ScreenUnits = ..., + outlinestipple: _Bitmap = ..., + state: Literal["normal", "active", "disabled"] = ..., + stipple: _Bitmap = ..., + tags: Union[str, Tuple[str, ...]] = ..., + width: _ScreenUnits = ..., + ) -> _CanvasItemId: ... + def create_polygon( + self, + __x0: float, + __y0: float, + __x1: float, + __y1: float, + *xy_pairs: float, + activedash: _Color = ..., + activefill: _Color = ..., + activeoutline: _Color = ..., + activeoutlinestipple: _Color = ..., + activestipple: str = ..., + activewidth: _ScreenUnits = ..., + dash: Union[Tuple[float], Tuple[float, float], Tuple[float, float, float, float]] = ..., + dashoffset: _ScreenUnits = ..., + disableddash: _Color = ..., + disabledfill: _Color = ..., + disabledoutline: _Color = ..., + disabledoutlinestipple: _Color = ..., + disabledstipple: _Bitmap = ..., + disabledwidth: _ScreenUnits = ..., + fill: _Color = ..., + joinstyle: Literal["round", "bevel", "miter"] = ..., + offset: _ScreenUnits = ..., + outline: _Color = ..., + outlineoffset: _ScreenUnits = ..., + outlinestipple: _Bitmap = ..., + smooth: bool = ..., + splinesteps: float = ..., + state: Literal["normal", "active", "disabled"] = ..., + stipple: _Bitmap = ..., + tags: Union[str, Tuple[str, ...]] = ..., + width: _ScreenUnits = ..., + ) -> _CanvasItemId: ... + def create_rectangle( + self, + __x0: float, + __y0: float, + __x1: float, + __y1: float, + *, + activedash: _Color = ..., + activefill: _Color = ..., + activeoutline: _Color = ..., + activeoutlinestipple: _Color = ..., + activestipple: str = ..., + activewidth: _ScreenUnits = ..., + dash: Union[Tuple[float], Tuple[float, float], Tuple[float, float, float, float]] = ..., + dashoffset: _ScreenUnits = ..., + disableddash: _Color = ..., + disabledfill: _Color = ..., + disabledoutline: _Color = ..., + disabledoutlinestipple: _Color = ..., + disabledstipple: _Bitmap = ..., + disabledwidth: _ScreenUnits = ..., + fill: _Color = ..., + offset: _ScreenUnits = ..., + outline: _Color = ..., + outlineoffset: _ScreenUnits = ..., + outlinestipple: _Bitmap = ..., + state: Literal["normal", "active", "disabled"] = ..., + stipple: _Bitmap = ..., + tags: Union[str, Tuple[str, ...]] = ..., + width: _ScreenUnits = ..., + ) -> _CanvasItemId: ... + def create_text( + self, + __x: float, + __y: float, + *, + activefill: _Color = ..., + activestipple: str = ..., + anchor: _Anchor = ..., + disabledfill: _Color = ..., + disabledstipple: _Bitmap = ..., + fill: _Color = ..., + font: _FontDescription = ..., + justify: Literal["left", "center", "right"] = ..., + offset: _ScreenUnits = ..., + state: Literal["normal", "active", "disabled"] = ..., + stipple: _Bitmap = ..., + tags: Union[str, Tuple[str, ...]] = ..., + text: Union[float, str] = ..., + width: _ScreenUnits = ..., + ) -> _CanvasItemId: ... + def create_window( + self, + __x: float, + __y: float, + *, + anchor: _Anchor = ..., + height: _ScreenUnits = ..., + state: Literal["normal", "active", "disabled"] = ..., + tags: Union[str, Tuple[str, ...]] = ..., + width: _ScreenUnits = ..., + window: Widget = ..., + ) -> _CanvasItemId: ... def dchars(self, *args): ... - def delete(self, *args): ... + def delete(self, *tagsOrCanvasIds: Union[str, _CanvasItemId]) -> None: ... def dtag(self, *args): ... def find(self, *args): ... - def find_above(self, tagOrId): ... + def find_above(self, tagOrId: Union[str, _CanvasItemId]): ... def find_all(self): ... - def find_below(self, tagOrId): ... + def find_below(self, tagOrId: Union[str, _CanvasItemId]): ... def find_closest(self, x, y, halo: Optional[Any] = ..., start: Optional[Any] = ...): ... def find_enclosed(self, x1, y1, x2, y2): ... def find_overlapping(self, x1, y1, x2, y2): ... - def find_withtag(self, tagOrId): ... + def find_withtag(self, tagOrId: Union[str, _CanvasItemId]): ... def focus(self, *args): ... def gettags(self, *args): ... def icursor(self, *args): ... @@ -1144,7 +1288,7 @@ class Canvas(Widget, XView, YView): lower: Any def move(self, *args): ... if sys.version_info >= (3, 8): - def moveto(self, tagOrId: Union[int, str], x: str = ..., y: str = ...) -> None: ... + def moveto(self, tagOrId: Union[str, _CanvasItemId], x: str = ..., y: str = ...) -> None: ... def postscript(self, cnf=..., **kw): ... def tag_raise(self, *args): ... lift: Any @@ -1209,7 +1353,7 @@ class Checkbutton(Widget): selectimage: _ImageSpec = ..., state: Literal["normal", "active", "disabled"] = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: Variable = ..., tristateimage: _ImageSpec = ..., tristatevalue: Any = ..., @@ -1257,7 +1401,7 @@ class Checkbutton(Widget): selectimage: _ImageSpec = ..., state: Literal["normal", "active", "disabled"] = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: Variable = ..., tristateimage: _ImageSpec = ..., tristatevalue: Any = ..., @@ -1471,7 +1615,7 @@ class Label(Widget): relief: _Relief = ..., state: Literal["normal", "active", "disabled"] = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: Variable = ..., underline: int = ..., width: _ScreenUnits = ..., @@ -1508,7 +1652,7 @@ class Label(Widget): relief: _Relief = ..., state: Literal["normal", "active", "disabled"] = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: Variable = ..., underline: int = ..., width: _ScreenUnits = ..., @@ -1937,7 +2081,7 @@ class Menubutton(Widget): relief: _Relief = ..., state: Literal["normal", "active", "disabled"] = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: Variable = ..., underline: int = ..., width: _ScreenUnits = ..., @@ -1977,7 +2121,7 @@ class Menubutton(Widget): relief: _Relief = ..., state: Literal["normal", "active", "disabled"] = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: Variable = ..., underline: int = ..., width: _ScreenUnits = ..., @@ -2013,7 +2157,7 @@ class Message(Widget): pady: _ScreenUnits = ..., relief: _Relief = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: Variable = ..., # there's width but no height width: _ScreenUnits = ..., @@ -2042,7 +2186,7 @@ class Message(Widget): pady: _ScreenUnits = ..., relief: _Relief = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: Variable = ..., width: _ScreenUnits = ..., ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... @@ -2089,7 +2233,7 @@ class Radiobutton(Widget): selectimage: _ImageSpec = ..., state: Literal["normal", "active", "disabled"] = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: Variable = ..., tristateimage: _ImageSpec = ..., tristatevalue: Any = ..., @@ -2136,7 +2280,7 @@ class Radiobutton(Widget): selectimage: _ImageSpec = ..., state: Literal["normal", "active", "disabled"] = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: Variable = ..., tristateimage: _ImageSpec = ..., tristatevalue: Any = ..., @@ -2529,11 +2673,7 @@ class Text(Widget, XView, YView): # tag_bind stuff is very similar to Canvas @overload def tag_bind( - self, - tagName: str, - sequence: Optional[str], - func: Optional[Callable[[Event[Text]], Any]], - add: Optional[bool] = ..., + self, tagName: str, sequence: Optional[str], func: Optional[Callable[[Event[Text]], Any]], add: Optional[bool] = ... ) -> str: ... @overload def tag_bind(self, tagName: str, sequence: Optional[str], func: str, add: Optional[bool] = ...) -> None: ... @@ -2869,7 +3009,7 @@ class LabelFrame(Widget): pady: _ScreenUnits = ..., relief: _Relief = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., visual: Union[str, Tuple[str, int]] = ..., width: _ScreenUnits = ..., ) -> None: ... @@ -2897,7 +3037,7 @@ class LabelFrame(Widget): pady: _ScreenUnits = ..., relief: _Relief = ..., takefocus: _TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., width: _ScreenUnits = ..., ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... @overload diff --git a/mypy/typeshed/stdlib/tkinter/ttk.pyi b/mypy/typeshed/stdlib/tkinter/ttk.pyi index 17aa24197f63..af3c75142598 100644 --- a/mypy/typeshed/stdlib/tkinter/ttk.pyi +++ b/mypy/typeshed/stdlib/tkinter/ttk.pyi @@ -49,7 +49,7 @@ class Button(Widget): state: str = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: tkinter.Variable = ..., underline: int = ..., width: Union[int, Literal[""]] = ..., @@ -68,7 +68,7 @@ class Button(Widget): state: str = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: tkinter.Variable = ..., underline: int = ..., width: Union[int, Literal[""]] = ..., @@ -95,7 +95,7 @@ class Checkbutton(Widget): state: str = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: tkinter.Variable = ..., underline: int = ..., # Seems like variable can be empty string, but actually setting it to @@ -119,7 +119,7 @@ class Checkbutton(Widget): state: str = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: tkinter.Variable = ..., underline: int = ..., variable: tkinter.Variable = ..., @@ -351,7 +351,7 @@ class Label(Widget): state: str = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: tkinter.Variable = ..., underline: int = ..., width: Union[int, Literal[""]] = ..., @@ -377,7 +377,7 @@ class Label(Widget): state: str = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: tkinter.Variable = ..., underline: int = ..., width: Union[int, Literal[""]] = ..., @@ -404,7 +404,7 @@ class Labelframe(Widget): relief: tkinter._Relief = ..., # undocumented style: str = ..., takefocus: tkinter._TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., underline: int = ..., width: tkinter._ScreenUnits = ..., ) -> None: ... @@ -423,7 +423,7 @@ class Labelframe(Widget): relief: tkinter._Relief = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., underline: int = ..., width: tkinter._ScreenUnits = ..., ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... @@ -449,7 +449,7 @@ class Menubutton(Widget): state: str = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: tkinter.Variable = ..., underline: int = ..., width: Union[int, Literal[""]] = ..., @@ -468,7 +468,7 @@ class Menubutton(Widget): state: str = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: tkinter.Variable = ..., underline: int = ..., width: Union[int, Literal[""]] = ..., @@ -622,7 +622,7 @@ class Radiobutton(Widget): state: str = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: tkinter.Variable = ..., underline: int = ..., value: Any = ..., @@ -642,7 +642,7 @@ class Radiobutton(Widget): state: str = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., - text: str = ..., + text: Union[float, str] = ..., textvariable: tkinter.Variable = ..., underline: int = ..., value: Any = ..., @@ -950,10 +950,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView): # Also, it's 'callback' instead of 'func' here. @overload def tag_bind( - self, - tagname: str, - sequence: Optional[str] = ..., - callback: Optional[Callable[[tkinter.Event[Treeview]], Any]] = ..., + self, tagname: str, sequence: Optional[str] = ..., callback: Optional[Callable[[tkinter.Event[Treeview]], Any]] = ... ) -> str: ... @overload def tag_bind(self, tagname: str, sequence: Optional[str], callback: str) -> None: ... diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi index 03aee05e3216..7f168a9196c2 100644 --- a/mypy/typeshed/stdlib/typing.pyi +++ b/mypy/typeshed/stdlib/typing.pyi @@ -603,12 +603,7 @@ if sys.version_info >= (3, 7): ] else: _get_type_hints_obj_allowed_types = Union[ - object, - Callable[..., Any], - FunctionType, - BuiltinFunctionType, - MethodType, - ModuleType, + object, Callable[..., Any], FunctionType, BuiltinFunctionType, MethodType, ModuleType, ] if sys.version_info >= (3, 9): @@ -621,9 +616,7 @@ if sys.version_info >= (3, 9): else: def get_type_hints( - obj: _get_type_hints_obj_allowed_types, - globalns: Optional[Dict[str, Any]] = ..., - localns: Optional[Dict[str, Any]] = ..., + obj: _get_type_hints_obj_allowed_types, globalns: Optional[Dict[str, Any]] = ..., localns: Optional[Dict[str, Any]] = ... ) -> Dict[str, Any]: ... if sys.version_info >= (3, 8): diff --git a/mypy/typeshed/stdlib/unittest/__init__.pyi b/mypy/typeshed/stdlib/unittest/__init__.pyi index aadaa610abbd..b94cc8d9c1cd 100644 --- a/mypy/typeshed/stdlib/unittest/__init__.pyi +++ b/mypy/typeshed/stdlib/unittest/__init__.pyi @@ -1,6 +1,20 @@ +import sys from typing import Optional from unittest.async_case import * -from unittest.case import * + +from .case import ( + FunctionTestCase as FunctionTestCase, + SkipTest as SkipTest, + TestCase as TestCase, + expectedFailure as expectedFailure, + skip as skip, + skipIf as skipIf, + skipUnless as skipUnless, +) + +if sys.version_info >= (3, 8): + from .case import addModuleCleanup as addModuleCleanup + from unittest.loader import * from unittest.main import * from unittest.result import TestResult as TestResult diff --git a/mypy/typeshed/stdlib/wsgiref/simple_server.pyi b/mypy/typeshed/stdlib/wsgiref/simple_server.pyi index 74511ece2bd5..4e0abd7e8e9d 100644 --- a/mypy/typeshed/stdlib/wsgiref/simple_server.pyi +++ b/mypy/typeshed/stdlib/wsgiref/simple_server.pyi @@ -33,6 +33,7 @@ class WSGIRequestHandler(BaseHTTPRequestHandler): def demo_app(environ: WSGIEnvironment, start_response: StartResponse) -> List[bytes]: ... _S = TypeVar("_S", bound=WSGIServer) + @overload def make_server(host: str, port: int, app: WSGIApplication, *, handler_class: Type[WSGIRequestHandler] = ...) -> WSGIServer: ... @overload diff --git a/mypy/typeshed/stdlib/zipfile.pyi b/mypy/typeshed/stdlib/zipfile.pyi index 941e79b968f0..91727aa540fb 100644 --- a/mypy/typeshed/stdlib/zipfile.pyi +++ b/mypy/typeshed/stdlib/zipfile.pyi @@ -186,6 +186,9 @@ class ZipInfo: def is_dir(self) -> bool: ... def FileHeader(self, zip64: Optional[bool] = ...) -> bytes: ... +class _PathOpenProtocol(Protocol): + def __call__(self, mode: str = ..., pwd: Optional[bytes] = ..., *, force_zip64: bool = ...) -> IO[bytes]: ... + if sys.version_info >= (3, 8): class Path: @property @@ -193,7 +196,11 @@ if sys.version_info >= (3, 8): @property def parent(self) -> Path: ... # undocumented def __init__(self, root: Union[ZipFile, StrPath, IO[bytes]], at: str = ...) -> None: ... - def open(self, mode: str = ..., pwd: Optional[bytes] = ..., *, force_zip64: bool = ...) -> IO[bytes]: ... + if sys.version_info >= (3, 9): + def open(self, mode: str = ..., pwd: Optional[bytes] = ..., *, force_zip64: bool = ...) -> IO[bytes]: ... + else: + @property + def open(self) -> _PathOpenProtocol: ... def iterdir(self) -> Iterator[Path]: ... def is_dir(self) -> bool: ... def is_file(self) -> bool: ...