Skip to content

Commit bf143d9

Browse files
jhanceAlexWaygood
andauthored
Sync typeshed (#13386)
Source commit: python/typeshed@a92da58 Co-authored-by: Alex Waygood <[email protected]>
1 parent 23146c4 commit bf143d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+922
-720
lines changed

mypy/test/teststubtest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(self, name, covariant: bool = ..., contravariant: bool = ...) -> No
5454
class ParamSpec:
5555
def __init__(self, name: str) -> None: ...
5656
57+
AnyStr = TypeVar("AnyStr", str, bytes)
5758
_T = TypeVar("_T")
5859
_T_co = TypeVar("_T_co", covariant=True)
5960
_K = TypeVar("_K")
@@ -64,7 +65,7 @@ def __init__(self, name: str) -> None: ...
6465
class Coroutine(Generic[_T_co, _S, _R]): ...
6566
class Iterable(Generic[_T_co]): ...
6667
class Mapping(Generic[_K, _V]): ...
67-
class Match(Generic[_T]): ...
68+
class Match(Generic[AnyStr]): ...
6869
class Sequence(Iterable[_T_co]): ...
6970
class Tuple(Sequence[_T_co]): ...
7071
def overload(func: _T) -> _T: ...

mypy/typeshed/stdlib/_compression.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ class DecompressReader(RawIOBase):
2020
trailing_error: type[Exception] | tuple[type[Exception], ...] = ...,
2121
**decomp_args: Any,
2222
) -> None: ...
23-
def readable(self) -> bool: ...
24-
def close(self) -> None: ...
25-
def seekable(self) -> bool: ...
2623
def readinto(self, b: WriteableBuffer) -> int: ...
2724
def read(self, size: int = ...) -> bytes: ...
2825
def seek(self, offset: int, whence: int = ...) -> int: ...
29-
def tell(self) -> int: ...

mypy/typeshed/stdlib/_decimal.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class Decimal:
7474
def from_float(cls: type[Self], __f: float) -> Self: ...
7575
def __bool__(self) -> bool: ...
7676
def compare(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
77-
def __hash__(self) -> int: ...
7877
def as_tuple(self) -> DecimalTuple: ...
7978
def as_integer_ratio(self) -> tuple[int, int]: ...
8079
def to_eng_string(self, context: Context | None = ...) -> str: ...
@@ -179,6 +178,11 @@ class _ContextManager:
179178
_TrapType: TypeAlias = type[DecimalException]
180179

181180
class Context:
181+
# TODO: Context doesn't allow you to delete *any* attributes from instances of the class at runtime,
182+
# even settable attributes like `prec` and `rounding`,
183+
# but that's inexpressable in the stub.
184+
# Type checkers either ignore it or misinterpret it
185+
# if you add a `def __delattr__(self, __name: str) -> NoReturn` method to the stub
182186
prec: int
183187
rounding: str
184188
Emin: int
@@ -199,9 +203,6 @@ class Context:
199203
traps: None | dict[_TrapType, bool] | Container[_TrapType] = ...,
200204
_ignored_flags: list[_TrapType] | None = ...,
201205
) -> None: ...
202-
# __setattr__() only allows to set a specific set of attributes,
203-
# already defined above.
204-
def __delattr__(self, __name: str) -> None: ...
205206
def __reduce__(self: Self) -> tuple[type[Self], tuple[Any, ...]]: ...
206207
def clear_flags(self) -> None: ...
207208
def clear_traps(self) -> None: ...

mypy/typeshed/stdlib/_dummy_thread.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def stack_size(size: int | None = ...) -> int: ...
1515

1616
class LockType:
1717
locked_status: bool
18-
def __init__(self) -> None: ...
1918
def acquire(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...
2019
def __enter__(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...
2120
def __exit__(self, typ: type[BaseException] | None, val: BaseException | None, tb: TracebackType | None) -> None: ...

mypy/typeshed/stdlib/_markupbase.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import sys
22
from typing import Any
33

44
class ParserBase:
5-
def __init__(self) -> None: ...
65
def reset(self) -> None: ...
76
def getpos(self) -> tuple[int, int]: ...
87
def unknown_decl(self, data: str) -> None: ...

mypy/typeshed/stdlib/_threading_local.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ _LocalDict: TypeAlias = dict[Any, Any]
88
class _localimpl:
99
key: str
1010
dicts: dict[int, tuple[ReferenceType[Any], _LocalDict]]
11-
def __init__(self) -> None: ...
1211
def get_dict(self) -> _LocalDict: ...
1312
def create_dict(self) -> _LocalDict: ...
1413

1514
class local:
1615
def __getattribute__(self, name: str) -> Any: ...
1716
def __setattr__(self, name: str, value: Any) -> None: ...
18-
def __delattr__(self, name: str) -> None: ...

mypy/typeshed/stdlib/_weakref.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class ReferenceType(Generic[_T]):
2323
__callback__: Callable[[ReferenceType[_T]], Any]
2424
def __new__(cls: type[Self], o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ...
2525
def __call__(self) -> _T | None: ...
26-
def __hash__(self) -> int: ...
2726
if sys.version_info >= (3, 9):
2827
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
2928

mypy/typeshed/stdlib/_weakrefset.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ class WeakSet(MutableSet[_T], Generic[_T]):
1717
@overload
1818
def __init__(self, data: Iterable[_T]) -> None: ...
1919
def add(self, item: _T) -> None: ...
20-
def clear(self) -> None: ...
2120
def discard(self, item: _T) -> None: ...
2221
def copy(self: Self) -> Self: ...
23-
def pop(self) -> _T: ...
2422
def remove(self, item: _T) -> None: ...
2523
def update(self, other: Iterable[_T]) -> None: ...
2624
def __contains__(self, item: object) -> bool: ...

mypy/typeshed/stdlib/array.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class array(MutableSequence[_T], Generic[_T]):
4747
def insert(self, __i: int, __v: _T) -> None: ...
4848
def pop(self, __i: int = ...) -> _T: ...
4949
def remove(self, __v: _T) -> None: ...
50-
def reverse(self) -> None: ...
5150
def tobytes(self) -> bytes: ...
5251
def tofile(self, __f: SupportsWrite[bytes]) -> None: ...
5352
def tolist(self) -> list[_T]: ...
@@ -56,7 +55,6 @@ class array(MutableSequence[_T], Generic[_T]):
5655
def fromstring(self, __buffer: bytes) -> None: ...
5756
def tostring(self) -> bytes: ...
5857

59-
def __contains__(self, __key: object) -> bool: ...
6058
def __len__(self) -> int: ...
6159
@overload
6260
def __getitem__(self, __i: SupportsIndex) -> _T: ...

mypy/typeshed/stdlib/ast.pyi

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@ from typing import Any, TypeVar, overload
55
from typing_extensions import Literal
66

77
if sys.version_info >= (3, 8):
8-
class Num(Constant):
8+
class _ABC(type):
9+
if sys.version_info >= (3, 9):
10+
def __init__(cls, *args: object) -> None: ...
11+
12+
class Num(Constant, metaclass=_ABC):
913
value: complex
1014

11-
class Str(Constant):
15+
class Str(Constant, metaclass=_ABC):
1216
value: str
1317
# Aliases for value, for backwards compatibility
1418
s: str
1519

16-
class Bytes(Constant):
20+
class Bytes(Constant, metaclass=_ABC):
1721
value: bytes
1822
# Aliases for value, for backwards compatibility
1923
s: bytes
2024

21-
class NameConstant(Constant): ...
22-
class Ellipsis(Constant): ...
25+
class NameConstant(Constant, metaclass=_ABC): ...
26+
class Ellipsis(Constant, metaclass=_ABC): ...
2327

2428
if sys.version_info >= (3, 9):
2529
class slice(AST): ...

0 commit comments

Comments
 (0)