Skip to content

Commit

Permalink
Sync typeshed
Browse files Browse the repository at this point in the history
  • Loading branch information
mypybot committed Apr 1, 2024
1 parent 4a7e5d3 commit a545760
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 36 deletions.
6 changes: 5 additions & 1 deletion mypy/typeshed/stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ class Array(_CData, Generic[_CT]):
def _type_(self) -> type[_CT]: ...
@_type_.setter
def _type_(self, value: type[_CT]) -> None: ...
raw: bytes # Note: only available if _CT == c_char
# Note: only available if _CT == c_char
@property
def raw(self) -> bytes: ...
@raw.setter
def raw(self, value: ReadableBuffer) -> None: ...
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
# TODO These methods cannot be annotated correctly at the moment.
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT
Expand Down
91 changes: 90 additions & 1 deletion mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ from typing import ( # noqa: Y022
from typing_extensions import ( # noqa: Y023
Concatenate,
Literal,
LiteralString,
ParamSpec,
Self,
TypeAlias,
Expand Down Expand Up @@ -433,16 +434,31 @@ class str(Sequence[str]):
def __new__(cls, object: object = ...) -> Self: ...
@overload
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
@overload
def capitalize(self: LiteralString) -> LiteralString: ...
@overload
def capitalize(self) -> str: ... # type: ignore[misc]
@overload
def casefold(self: LiteralString) -> LiteralString: ...
@overload
def casefold(self) -> str: ... # type: ignore[misc]
@overload
def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
@overload
def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
def count(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
def endswith(
self, suffix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
) -> bool: ...
@overload
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
@overload
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
def find(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
@overload
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
@overload
def format(self, *args: object, **kwargs: object) -> str: ...
def format_map(self, map: _FormatMapMapping) -> str: ...
def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
Expand All @@ -458,32 +474,89 @@ class str(Sequence[str]):
def isspace(self) -> bool: ...
def istitle(self) -> bool: ...
def isupper(self) -> bool: ...
@overload
def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ...
@overload
def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc]
@overload
def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
@overload
def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
@overload
def lower(self: LiteralString) -> LiteralString: ...
@overload
def lower(self) -> str: ... # type: ignore[misc]
@overload
def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
@overload
def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
@overload
def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
@overload
def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
@overload
def replace(self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, /) -> LiteralString: ...
@overload
def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc]
if sys.version_info >= (3, 9):
@overload
def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ...
@overload
def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc]
@overload
def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ...
@overload
def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc]

def rfind(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
def rindex(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
@overload
def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
@overload
def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
@overload
def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
@overload
def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
@overload
def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
@overload
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
@overload
def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
@overload
def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
@overload
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
@overload
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
@overload
def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
@overload
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
def startswith(
self, prefix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
) -> bool: ...
@overload
def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
@overload
def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
@overload
def swapcase(self: LiteralString) -> LiteralString: ...
@overload
def swapcase(self) -> str: ... # type: ignore[misc]
@overload
def title(self: LiteralString) -> LiteralString: ...
@overload
def title(self) -> str: ... # type: ignore[misc]
def translate(self, table: _TranslateTable, /) -> str: ...
@overload
def upper(self: LiteralString) -> LiteralString: ...
@overload
def upper(self) -> str: ... # type: ignore[misc]
@overload
def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ...
@overload
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
@staticmethod
@overload
Expand All @@ -494,6 +567,9 @@ class str(Sequence[str]):
@staticmethod
@overload
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
@overload
def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ...
@overload
def __add__(self, value: str, /) -> str: ... # type: ignore[misc]
# Incompatible with Sequence.__contains__
def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
Expand All @@ -502,13 +578,25 @@ class str(Sequence[str]):
def __getitem__(self, key: SupportsIndex | slice, /) -> str: ...
def __gt__(self, value: str, /) -> bool: ...
def __hash__(self) -> int: ...
@overload
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
@overload
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
def __le__(self, value: str, /) -> bool: ...
def __len__(self) -> int: ...
def __lt__(self, value: str, /) -> bool: ...
@overload
def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ...
@overload
def __mod__(self, value: Any, /) -> str: ...
@overload
def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
@overload
def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
def __ne__(self, value: object, /) -> bool: ...
@overload
def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
@overload
def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
def __getnewargs__(self) -> tuple[str]: ...

Expand Down Expand Up @@ -1596,7 +1684,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
# without creating many false-positive errors (see #7578).
# Instead, we special-case the most common examples of this: bool and literal integers.
@overload
def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ... # type: ignore[overload-overlap]
def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ... # type: ignore[overload-overlap]
@overload
def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ...
@overload
Expand Down Expand Up @@ -1777,6 +1865,7 @@ class MemoryError(Exception): ...

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

class ReferenceError(Exception): ...
Expand Down
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/dataclasses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class InitVar(Generic[_T], metaclass=_InitVarMeta):
if sys.version_info >= (3, 12):
def make_dataclass(
cls_name: str,
fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]],
fields: Iterable[str | tuple[str, Any] | tuple[str, Any, Any]],
*,
bases: tuple[type, ...] = (),
namespace: dict[str, Any] | None = None,
Expand All @@ -263,7 +263,7 @@ if sys.version_info >= (3, 12):
elif sys.version_info >= (3, 11):
def make_dataclass(
cls_name: str,
fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]],
fields: Iterable[str | tuple[str, Any] | tuple[str, Any, Any]],
*,
bases: tuple[type, ...] = (),
namespace: dict[str, Any] | None = None,
Expand All @@ -282,7 +282,7 @@ elif sys.version_info >= (3, 11):
elif sys.version_info >= (3, 10):
def make_dataclass(
cls_name: str,
fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]],
fields: Iterable[str | tuple[str, Any] | tuple[str, Any, Any]],
*,
bases: tuple[type, ...] = (),
namespace: dict[str, Any] | None = None,
Expand All @@ -300,7 +300,7 @@ elif sys.version_info >= (3, 10):
else:
def make_dataclass(
cls_name: str,
fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]],
fields: Iterable[str | tuple[str, Any] | tuple[str, Any, Any]],
*,
bases: tuple[type, ...] = (),
namespace: dict[str, Any] | None = None,
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/importlib/resources/simple.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ if sys.version_info >= (3, 11):
def is_file(self) -> Literal[True]: ...
def is_dir(self) -> Literal[False]: ...
@overload
def open(self, mode: OpenTextMode = "r", *args: Incomplete, **kwargs: Incomplete) -> TextIOWrapper: ...
def open(self, mode: OpenTextMode = "r", *args, **kwargs) -> TextIOWrapper: ...
@overload
def open(self, mode: OpenBinaryMode, *args: Unused, **kwargs: Unused) -> BinaryIO: ...
@overload
def open(self, mode: str, *args: Incomplete, **kwargs: Incomplete) -> IO[Any]: ...
def open(self, mode: str, *args: Incomplete, **kwargs) -> IO[Any]: ...
def joinpath(self, name: Never) -> NoReturn: ... # type: ignore[override]

class ResourceContainer(Traversable, metaclass=abc.ABCMeta):
Expand Down
6 changes: 3 additions & 3 deletions mypy/typeshed/stdlib/multiprocessing/resource_tracker.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from _typeshed import FileDescriptorOrPath, Incomplete
from _typeshed import FileDescriptorOrPath
from collections.abc import Sized

__all__ = ["ensure_running", "register", "unregister"]

class ResourceTracker:
def getfd(self) -> int | None: ...
def ensure_running(self) -> None: ...
def register(self, name: Sized, rtype: Incomplete) -> None: ...
def unregister(self, name: Sized, rtype: Incomplete) -> None: ...
def register(self, name: Sized, rtype) -> None: ...
def unregister(self, name: Sized, rtype) -> None: ...

_resource_tracker: ResourceTracker
ensure_running = _resource_tracker.ensure_running
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/multiprocessing/util.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def is_abstract_socket_namespace(address: str | bytes | None) -> bool: ...
abstract_sockets_supported: bool

def get_temp_dir() -> str: ...
def register_after_fork(obj: Incomplete, func: Callable[[Incomplete], object]) -> None: ...
def register_after_fork(obj, func: Callable[[Incomplete], object]) -> None: ...

class Finalize:
def __init__(
Expand All @@ -59,7 +59,7 @@ class Finalize:
_finalizer_registry: MutableMapping[Incomplete, Incomplete] = {},
sub_debug: Callable[..., object] = ...,
getpid: Callable[[], int] = ...,
) -> Incomplete: ...
): ...
def cancel(self) -> None: ...
def still_active(self) -> bool: ...

Expand Down
2 changes: 2 additions & 0 deletions mypy/typeshed/stdlib/pyexpat/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class XMLParserType:
def ExternalEntityParserCreate(self, context: str | None, encoding: str = ..., /) -> XMLParserType: ...
def SetParamEntityParsing(self, flag: int, /) -> int: ...
def UseForeignDTD(self, flag: bool = True, /) -> None: ...
def GetReparseDeferralEnabled(self) -> bool: ...
def SetReparseDeferralEnabled(self, enabled: bool, /) -> None: ...
@property
def intern(self) -> dict[str, str]: ...
buffer_size: int
Expand Down
8 changes: 2 additions & 6 deletions mypy/typeshed/stdlib/signal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,8 @@ else:
@property
def si_band(self) -> int: ...

if sys.version_info >= (3, 10):
def sigtimedwait(sigset: Iterable[int], timeout: float, /) -> struct_siginfo | None: ...
def sigwaitinfo(sigset: Iterable[int], /) -> struct_siginfo: ...
else:
def sigtimedwait(sigset: Iterable[int], timeout: float) -> struct_siginfo | None: ...
def sigwaitinfo(sigset: Iterable[int]) -> struct_siginfo: ...
def sigtimedwait(sigset: Iterable[int], timeout: float, /) -> struct_siginfo | None: ...
def sigwaitinfo(sigset: Iterable[int], /) -> struct_siginfo: ...

def strsignal(signalnum: _SIGNUM, /) -> str | None: ...
def valid_signals() -> set[Signals]: ...
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/tkinter/commondialog.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class Dialog:
command: ClassVar[str | None]
master: Incomplete | None
options: Mapping[str, Incomplete]
def __init__(self, master: Incomplete | None = None, **options: Incomplete) -> None: ...
def show(self, **options: Incomplete) -> Incomplete: ...
def __init__(self, master: Incomplete | None = None, **options) -> None: ...
def show(self, **options): ...
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/tkinter/dialog.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ DIALOG_ICON: str
class Dialog(Widget):
widgetName: str
num: int
def __init__(self, master: Incomplete | None = None, cnf: Mapping[str, Any] = {}, **kw: Incomplete) -> None: ...
def __init__(self, master: Incomplete | None = None, cnf: Mapping[str, Any] = {}, **kw) -> None: ...
def destroy(self) -> None: ...
3 changes: 1 addition & 2 deletions mypy/typeshed/stdlib/tkinter/scrolledtext.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from _typeshed import Incomplete
from tkinter import Frame, Misc, Scrollbar, Text

__all__ = ["ScrolledText"]
Expand All @@ -7,4 +6,4 @@ __all__ = ["ScrolledText"]
class ScrolledText(Text):
frame: Frame
vbar: Scrollbar
def __init__(self, master: Misc | None = None, **kwargs: Incomplete) -> None: ...
def __init__(self, master: Misc | None = None, **kwargs) -> None: ...
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/traceback.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ __all__ = [
"walk_tb",
]

_PT: TypeAlias = tuple[str, int, str, str | None]
_FrameSummaryTuple: TypeAlias = tuple[str, int, str, str | None]

def print_tb(tb: TracebackType | None, limit: int | None = None, file: SupportsWrite[str] | None = None) -> None: ...

Expand Down Expand Up @@ -80,10 +80,10 @@ def print_last(limit: int | None = None, file: SupportsWrite[str] | None = None,
def print_stack(f: FrameType | None = None, limit: int | None = None, file: SupportsWrite[str] | None = None) -> None: ...
def extract_tb(tb: TracebackType | None, limit: int | None = None) -> StackSummary: ...
def extract_stack(f: FrameType | None = None, limit: int | None = None) -> StackSummary: ...
def format_list(extracted_list: list[FrameSummary]) -> list[str]: ...
def format_list(extracted_list: Iterable[FrameSummary | _FrameSummaryTuple]) -> list[str]: ...

# undocumented
def print_list(extracted_list: list[FrameSummary], file: SupportsWrite[str] | None = None) -> None: ...
def print_list(extracted_list: Iterable[FrameSummary | _FrameSummaryTuple], file: SupportsWrite[str] | None = None) -> None: ...

if sys.version_info >= (3, 10):
@overload
Expand Down Expand Up @@ -255,7 +255,7 @@ class StackSummary(list[FrameSummary]):
capture_locals: bool = False,
) -> StackSummary: ...
@classmethod
def from_list(cls, a_list: Iterable[FrameSummary | _PT]) -> StackSummary: ...
def from_list(cls, a_list: Iterable[FrameSummary | _FrameSummaryTuple]) -> StackSummary: ...
if sys.version_info >= (3, 11):
def format_frame_summary(self, frame_summary: FrameSummary) -> str: ...

Expand Down
10 changes: 5 additions & 5 deletions mypy/typeshed/stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import collections # noqa: F401 # pyright: ignore
import sys
import typing_extensions
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import IdentityFunction, Incomplete, ReadableBuffer, SupportsKeysAndGetItem
from _typeshed import IdentityFunction, ReadableBuffer, SupportsKeysAndGetItem
from abc import ABCMeta, abstractmethod
from contextlib import AbstractAsyncContextManager, AbstractContextManager
from re import Match as Match, Pattern as Pattern
Expand Down Expand Up @@ -170,7 +170,7 @@ class TypeVar:
def __or__(self, right: Any) -> _SpecialForm: ...
def __ror__(self, left: Any) -> _SpecialForm: ...
if sys.version_info >= (3, 11):
def __typing_subst__(self, arg: Incomplete) -> Incomplete: ...
def __typing_subst__(self, arg): ...

# Used for an undocumented mypy feature. Does not exist at runtime.
_promote = object()
Expand Down Expand Up @@ -221,7 +221,7 @@ if sys.version_info >= (3, 11):
def __init__(self, name: str) -> None: ...
def __iter__(self) -> Any: ...
def __typing_subst__(self, arg: Never) -> Never: ...
def __typing_prepare_subst__(self, alias: Incomplete, args: Incomplete) -> Incomplete: ...
def __typing_prepare_subst__(self, alias, args): ...

if sys.version_info >= (3, 10):
@final
Expand Down Expand Up @@ -270,8 +270,8 @@ if sys.version_info >= (3, 10):
@property
def kwargs(self) -> ParamSpecKwargs: ...
if sys.version_info >= (3, 11):
def __typing_subst__(self, arg: Incomplete) -> Incomplete: ...
def __typing_prepare_subst__(self, alias: Incomplete, args: Incomplete) -> Incomplete: ...
def __typing_subst__(self, arg): ...
def __typing_prepare_subst__(self, alias, args): ...

def __or__(self, right: Any) -> _SpecialForm: ...
def __ror__(self, left: Any) -> _SpecialForm: ...
Expand Down
Loading

0 comments on commit a545760

Please sign in to comment.