Skip to content

Commit

Permalink
Sync typeshed
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Jun 20, 2024
1 parent 94597d9 commit 53cf24f
Show file tree
Hide file tree
Showing 42 changed files with 707 additions and 176 deletions.
3 changes: 2 additions & 1 deletion mypy/typeshed/stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ array: 3.0-
ast: 3.0-
asynchat: 3.0-3.11
asyncio: 3.4-
asyncio.mixins: 3.10-
asyncio.exceptions: 3.8-
asyncio.format_helpers: 3.7-
asyncio.mixins: 3.10-
asyncio.runners: 3.7-
asyncio.staggered: 3.8-
asyncio.taskgroups: 3.11-
Expand Down Expand Up @@ -270,6 +270,7 @@ threading: 3.0-
time: 3.0-
timeit: 3.0-
tkinter: 3.0-
tkinter.tix: 3.0-3.12
token: 3.0-
tokenize: 3.0-
tomllib: 3.11-
Expand Down
5 changes: 4 additions & 1 deletion mypy/typeshed/stdlib/_ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ PyCF_ONLY_AST: Literal[1024]
PyCF_TYPE_COMMENTS: Literal[4096]
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]

if sys.version_info >= (3, 13):
PyCF_OPTIMIZED_AST: Literal[33792]

# Used for node end positions in constructor keyword arguments
_EndPositionT = typing_extensions.TypeVar("_EndPositionT", int, int | None, default=int | None) # noqa: Y023
_EndPositionT = typing_extensions.TypeVar("_EndPositionT", int, int | None, default=int | None)

# Alias used for fields that must always be valid identifiers
# A string `x` counts as a valid identifier if both the following are True
Expand Down
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
3 changes: 1 addition & 2 deletions mypy/typeshed/stdlib/_curses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ A_COLOR: int
A_DIM: int
A_HORIZONTAL: int
A_INVIS: int
if sys.platform != "darwin":
A_ITALIC: int
A_ITALIC: int
A_LEFT: int
A_LOW: int
A_NORMAL: int
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/_json.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ class make_scanner:
def __init__(self, context: make_scanner) -> None: ...
def __call__(self, string: str, index: int) -> tuple[Any, int]: ...

def encode_basestring_ascii(s: str) -> str: ...
def encode_basestring_ascii(s: str, /) -> str: ...
def scanstring(string: str, end: int, strict: bool = ...) -> tuple[str, int]: ...
7 changes: 7 additions & 0 deletions mypy/typeshed/stdlib/_tkinter.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sys
from collections.abc import Callable
from typing import Any, ClassVar, Literal, final
from typing_extensions import TypeAlias

# _tkinter is meant to be only used internally by tkinter, but some tkinter
# functions e.g. return _tkinter.Tcl_Obj objects. Tcl_Obj represents a Tcl
Expand Down Expand Up @@ -30,6 +32,8 @@ class Tcl_Obj:

class TclError(Exception): ...

_TkinterTraceFunc: TypeAlias = Callable[[tuple[str, ...]], object]

# This class allows running Tcl code. Tkinter uses it internally a lot, and
# it's often handy to drop a piece of Tcl code into a tkinter program. Example:
#
Expand Down Expand Up @@ -86,6 +90,9 @@ class TkappType:
def unsetvar(self, *args, **kwargs): ...
def wantobjects(self, *args, **kwargs): ...
def willdispatch(self): ...
if sys.version_info >= (3, 12):
def gettrace(self, /) -> _TkinterTraceFunc | None: ...
def settrace(self, func: _TkinterTraceFunc | None, /) -> None: ...

# These should be kept in sync with tkinter.tix constants, except ALL_EVENTS which doesn't match TCL_ALL_EVENTS
ALL_EVENTS: Literal[-3]
Expand Down
5 changes: 3 additions & 2 deletions mypy/typeshed/stdlib/_weakref.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class ProxyType(Generic[_T]): # "weakproxy"
def __getattr__(self, attr: str) -> Any: ...

class ReferenceType(Generic[_T]):
__callback__: Callable[[ReferenceType[_T]], Any]
def __new__(cls, o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ..., /) -> Self: ...
__callback__: Callable[[Self], Any]
def __new__(cls, o: _T, callback: Callable[[Self], Any] | None = ..., /) -> Self: ...
def __init__(self, o: _T, callback: Callable[[Self], Any] | None = ..., /) -> None: ...
def __call__(self) -> _T | None: ...
def __eq__(self, value: object, /) -> bool: ...
def __hash__(self) -> int: ...
Expand Down
3 changes: 3 additions & 0 deletions mypy/typeshed/stdlib/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,6 @@ def walk(node: AST) -> Iterator[AST]: ...

if sys.version_info >= (3, 9):
def main() -> None: ...

if sys.version_info >= (3, 14):
def compare(left: AST, right: AST, /, *, compare_attributes: bool = False) -> bool: ...
111 changes: 108 additions & 3 deletions 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 @@ -434,18 +435,33 @@ 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 format_map(self, mapping: _FormatMapMapping, /) -> str: ...
def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
def isalnum(self) -> bool: ...
def isalpha(self) -> bool: ...
Expand All @@ -459,32 +475,99 @@ 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]
def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc]
if sys.version_info >= (3, 13):
@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]
else:
@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 @@ -495,6 +578,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 @@ -503,13 +589,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 @@ -1126,6 +1224,9 @@ class property:
fset: Callable[[Any, Any], None] | None
fdel: Callable[[Any], None] | None
__isabstractmethod__: bool
if sys.version_info >= (3, 13):
__name__: str

def __init__(
self,
fget: Callable[[Any], Any] | None = ...,
Expand Down Expand Up @@ -1631,7 +1732,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 @@ -1969,3 +2070,7 @@ if sys.version_info >= (3, 11):
def split(
self, condition: Callable[[_ExceptionT_co | Self], bool], /
) -> tuple[ExceptionGroup[_ExceptionT_co] | None, ExceptionGroup[_ExceptionT_co] | None]: ...

if sys.version_info >= (3, 13):
class IncompleteInputError(SyntaxError): ...
class PythonFinalizationError(RuntimeError): ...
Loading

0 comments on commit 53cf24f

Please sign in to comment.