Skip to content

Commit

Permalink
Sync typeshed
Browse files Browse the repository at this point in the history
  • Loading branch information
koogoro committed Feb 17, 2023
1 parent bcf60ac commit 939680e
Show file tree
Hide file tree
Showing 130 changed files with 1,135 additions and 1,010 deletions.
26 changes: 13 additions & 13 deletions mypy/typeshed/stdlib/_codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -104,35 +104,35 @@ if sys.version_info < (3, 8):
def unicode_internal_decode(__obj: str | ReadableBuffer, __errors: str | None = None) -> tuple[str, int]: ...
def unicode_internal_encode(__obj: str | ReadableBuffer, __errors: str | None = None) -> tuple[bytes, int]: ...

def utf_16_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
def utf_16_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
def utf_16_be_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
def utf_16_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
def utf_16_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
def utf_16_encode(__str: str, __errors: str | None = None, __byteorder: int = 0) -> tuple[bytes, int]: ...
def utf_16_ex_decode(
__data: ReadableBuffer, __errors: str | None = None, __byteorder: int = 0, __final: int = False
__data: ReadableBuffer, __errors: str | None = None, __byteorder: int = 0, __final: bool = False
) -> tuple[str, int, int]: ...
def utf_16_le_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
def utf_16_le_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
def utf_16_le_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
def utf_32_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
def utf_32_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
def utf_32_be_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
def utf_32_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
def utf_32_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
def utf_32_encode(__str: str, __errors: str | None = None, __byteorder: int = 0) -> tuple[bytes, int]: ...
def utf_32_ex_decode(
__data: ReadableBuffer, __errors: str | None = None, __byteorder: int = 0, __final: int = False
__data: ReadableBuffer, __errors: str | None = None, __byteorder: int = 0, __final: bool = False
) -> tuple[str, int, int]: ...
def utf_32_le_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
def utf_32_le_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
def utf_32_le_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
def utf_7_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
def utf_7_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
def utf_7_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
def utf_8_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
def utf_8_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
def utf_8_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...

if sys.platform == "win32":
def mbcs_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
def mbcs_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
def mbcs_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
def code_page_decode(
__codepage: int, __data: ReadableBuffer, __errors: str | None = None, __final: int = False
__codepage: int, __data: ReadableBuffer, __errors: str | None = None, __final: bool = False
) -> tuple[str, int]: ...
def code_page_encode(__code_page: int, __str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
def oem_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
def oem_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
def oem_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/_csv.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from _typeshed import SupportsWrite
from collections.abc import Iterable, Iterator
from typing import Any, Union
from typing_extensions import Literal, TypeAlias
from typing import Any
from typing_extensions import Final, Literal, TypeAlias

__version__: str
__version__: Final[str]

QUOTE_ALL: Literal[1]
QUOTE_MINIMAL: Literal[0]
Expand All @@ -27,7 +27,7 @@ class Dialect:
strict: bool
def __init__(self) -> None: ...

_DialectLike: TypeAlias = Union[str, Dialect, type[Dialect]]
_DialectLike: TypeAlias = str | Dialect | type[Dialect]

class _reader(Iterator[list[str]]):
@property
Expand Down
23 changes: 11 additions & 12 deletions mypy/typeshed/stdlib/_decimal.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import numbers
import sys
from _typeshed import Self
from collections.abc import Container, Sequence
from types import TracebackType
from typing import Any, ClassVar, NamedTuple, Union, overload
from typing_extensions import Literal, TypeAlias
from typing import Any, ClassVar, NamedTuple, overload
from typing_extensions import Final, Literal, Self, TypeAlias

_Decimal: TypeAlias = Decimal | int
_DecimalNew: TypeAlias = Union[Decimal, float, str, tuple[int, Sequence[int], int]]
_DecimalNew: TypeAlias = Decimal | float | str | tuple[int, Sequence[int], int]
_ComparableNum: TypeAlias = Decimal | float | numbers.Rational

__version__: str
__libmpdec_version__: str
__version__: Final[str]
__libmpdec_version__: Final[str]

class DecimalTuple(NamedTuple):
sign: int
Expand Down Expand Up @@ -69,9 +68,9 @@ else:
def localcontext(ctx: Context | None = None) -> _ContextManager: ...

class Decimal:
def __new__(cls: type[Self], value: _DecimalNew = ..., context: Context | None = ...) -> Self: ...
def __new__(cls, value: _DecimalNew = ..., context: Context | None = ...) -> Self: ...
@classmethod
def from_float(cls: type[Self], __f: float) -> Self: ...
def from_float(cls, __f: float) -> Self: ...
def __bool__(self) -> bool: ...
def compare(self, other: _Decimal, context: Context | None = None) -> Decimal: ...
def as_tuple(self) -> DecimalTuple: ...
Expand Down Expand Up @@ -163,9 +162,9 @@ class Decimal:
def rotate(self, other: _Decimal, context: Context | None = None) -> Decimal: ...
def scaleb(self, other: _Decimal, context: Context | None = None) -> Decimal: ...
def shift(self, other: _Decimal, context: Context | None = None) -> Decimal: ...
def __reduce__(self: Self) -> tuple[type[Self], tuple[str]]: ...
def __copy__(self: Self) -> Self: ...
def __deepcopy__(self: Self, __memo: Any) -> Self: ...
def __reduce__(self) -> tuple[type[Self], tuple[str]]: ...
def __copy__(self) -> Self: ...
def __deepcopy__(self, __memo: Any) -> Self: ...
def __format__(self, __specifier: str, __context: Context | None = ...) -> str: ...

class _ContextManager:
Expand Down Expand Up @@ -203,7 +202,7 @@ class Context:
traps: None | dict[_TrapType, bool] | Container[_TrapType] = ...,
_ignored_flags: list[_TrapType] | None = ...,
) -> None: ...
def __reduce__(self: Self) -> tuple[type[Self], tuple[Any, ...]]: ...
def __reduce__(self) -> tuple[type[Self], tuple[Any, ...]]: ...
def clear_flags(self) -> None: ...
def clear_traps(self) -> None: ...
def copy(self) -> Context: ...
Expand Down
3 changes: 2 additions & 1 deletion mypy/typeshed/stdlib/_heapq.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Any, TypeVar
from typing_extensions import Final

_T = TypeVar("_T")

__about__: str
__about__: Final[str]

def heapify(__heap: list[Any]) -> None: ...
def heappop(__heap: list[_T]) -> _T: ...
Expand Down
6 changes: 4 additions & 2 deletions mypy/typeshed/stdlib/_py_abc.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Self
import _typeshed
from typing import Any, NewType, TypeVar

_T = TypeVar("_T")
Expand All @@ -8,5 +8,7 @@ _CacheToken = NewType("_CacheToken", int)
def get_cache_token() -> _CacheToken: ...

class ABCMeta(type):
def __new__(__mcls: type[Self], __name: str, __bases: tuple[type[Any], ...], __namespace: dict[str, Any]) -> Self: ...
def __new__(
__mcls: type[_typeshed.Self], __name: str, __bases: tuple[type[Any], ...], __namespace: dict[str, Any]
) -> _typeshed.Self: ...
def register(cls, subclass: type[_T]) -> type[_T]: ...
12 changes: 10 additions & 2 deletions mypy/typeshed/stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import mmap
import pickle
import sys
from collections.abc import Awaitable, Callable, Iterable, Set as AbstractSet
from dataclasses import Field
from os import PathLike
from types import FrameType, TracebackType
from typing import Any, AnyStr, Generic, Protocol, TypeVar, Union
from typing import Any, AnyStr, ClassVar, Generic, Protocol, TypeVar
from typing_extensions import Final, Literal, LiteralString, TypeAlias, final

_KT = TypeVar("_KT")
Expand Down Expand Up @@ -264,7 +265,7 @@ IndexableBuffer: TypeAlias = bytes | bytearray | memoryview | array.array[Any] |
# def __buffer__(self, __flags: int) -> memoryview: ...

ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType]
OptExcInfo: TypeAlias = Union[ExcInfo, tuple[None, None, None]]
OptExcInfo: TypeAlias = ExcInfo | tuple[None, None, None]

# stable
if sys.version_info >= (3, 10):
Expand Down Expand Up @@ -304,3 +305,10 @@ ProfileFunction: TypeAlias = Callable[[FrameType, str, Any], object]

# Objects suitable to be passed to sys.settrace, threading.settrace, and similar
TraceFunction: TypeAlias = Callable[[FrameType, str, Any], TraceFunction | None]

# experimental
# Might not work as expected for pyright, see
# https://github.com/python/typeshed/pull/9362
# https://github.com/microsoft/pyright/issues/4339
class DataclassInstance(Protocol):
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]
5 changes: 2 additions & 3 deletions mypy/typeshed/stdlib/_weakref.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import sys
from _typeshed import Self
from collections.abc import Callable
from typing import Any, Generic, TypeVar, overload
from typing_extensions import final
from typing_extensions import Self, final

if sys.version_info >= (3, 9):
from types import GenericAlias
Expand All @@ -21,7 +20,7 @@ class ProxyType(Generic[_T]): # "weakproxy"

class ReferenceType(Generic[_T]):
__callback__: Callable[[ReferenceType[_T]], Any]
def __new__(cls: type[Self], o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ...
def __new__(cls, o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ...
def __call__(self) -> _T | None: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
Expand Down
20 changes: 10 additions & 10 deletions mypy/typeshed/stdlib/_weakrefset.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from _typeshed import Self
from collections.abc import Iterable, Iterator, MutableSet
from typing import Any, Generic, TypeVar, overload
from typing_extensions import Self

if sys.version_info >= (3, 9):
from types import GenericAlias
Expand All @@ -18,21 +18,21 @@ class WeakSet(MutableSet[_T], Generic[_T]):
def __init__(self, data: Iterable[_T]) -> None: ...
def add(self, item: _T) -> None: ...
def discard(self, item: _T) -> None: ...
def copy(self: Self) -> Self: ...
def copy(self) -> Self: ...
def remove(self, item: _T) -> None: ...
def update(self, other: Iterable[_T]) -> None: ...
def __contains__(self, item: object) -> bool: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[_T]: ...
def __ior__(self: Self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc]
def difference(self: Self, other: Iterable[_T]) -> Self: ...
def __sub__(self: Self, other: Iterable[Any]) -> Self: ...
def __ior__(self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc]
def difference(self, other: Iterable[_T]) -> Self: ...
def __sub__(self, other: Iterable[Any]) -> Self: ...
def difference_update(self, other: Iterable[Any]) -> None: ...
def __isub__(self: Self, other: Iterable[Any]) -> Self: ...
def intersection(self: Self, other: Iterable[_T]) -> Self: ...
def __and__(self: Self, other: Iterable[Any]) -> Self: ...
def __isub__(self, other: Iterable[Any]) -> Self: ...
def intersection(self, other: Iterable[_T]) -> Self: ...
def __and__(self, other: Iterable[Any]) -> Self: ...
def intersection_update(self, other: Iterable[Any]) -> None: ...
def __iand__(self: Self, other: Iterable[Any]) -> Self: ...
def __iand__(self, other: Iterable[Any]) -> Self: ...
def issubset(self, other: Iterable[_T]) -> bool: ...
def __le__(self, other: Iterable[_T]) -> bool: ...
def __lt__(self, other: Iterable[_T]) -> bool: ...
Expand All @@ -43,7 +43,7 @@ class WeakSet(MutableSet[_T], Generic[_T]):
def symmetric_difference(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
def __xor__(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
def symmetric_difference_update(self, other: Iterable[_T]) -> None: ...
def __ixor__(self: Self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc]
def __ixor__(self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc]
def union(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
def __or__(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
def isdisjoint(self, other: Iterable[_T]) -> bool: ...
Expand Down

0 comments on commit 939680e

Please sign in to comment.