mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 05:24:52 +08:00
Backport many Self-related changes to the Python-2 stdlib (#7128)
This commit is contained in:
@@ -751,7 +751,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]):
|
||||
|
||||
class enumerate(Iterator[tuple[int, _T]], Generic[_T]):
|
||||
def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ...
|
||||
def __iter__(self) -> Iterator[tuple[int, _T]]: ...
|
||||
def __iter__(self: Self) -> Self: ...
|
||||
def next(self) -> tuple[int, _T]: ...
|
||||
|
||||
class xrange(Sized, Iterable[int], Reversible[int]):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import Self
|
||||
from types import TracebackType
|
||||
from typing import Any, Union
|
||||
|
||||
@@ -88,7 +89,7 @@ if sys.platform == "win32":
|
||||
class HKEYType:
|
||||
def __bool__(self) -> bool: ...
|
||||
def __int__(self) -> int: ...
|
||||
def __enter__(self) -> HKEYType: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> bool | None: ...
|
||||
|
||||
@@ -751,7 +751,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]):
|
||||
|
||||
class enumerate(Iterator[tuple[int, _T]], Generic[_T]):
|
||||
def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ...
|
||||
def __iter__(self) -> Iterator[tuple[int, _T]]: ...
|
||||
def __iter__(self: Self) -> Self: ...
|
||||
def next(self) -> tuple[int, _T]: ...
|
||||
|
||||
class xrange(Sized, Iterable[int], Reversible[int]):
|
||||
|
||||
@@ -85,7 +85,7 @@ class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
|
||||
def incrementaldecoder(self) -> _IncrementalDecoder: ...
|
||||
name: str
|
||||
def __new__(
|
||||
cls,
|
||||
cls: type[Self],
|
||||
encode: _Encoder,
|
||||
decode: _Decoder,
|
||||
streamreader: _StreamReader | None = ...,
|
||||
@@ -95,7 +95,7 @@ class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
|
||||
name: str | None = ...,
|
||||
*,
|
||||
_is_text_encoding: bool | None = ...,
|
||||
) -> CodecInfo: ...
|
||||
) -> Self: ...
|
||||
|
||||
def getencoder(encoding: str) -> _Encoder: ...
|
||||
def getdecoder(encoding: str) -> _Decoder: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from types import TracebackType
|
||||
from typing import Iterator, MutableMapping, Union
|
||||
from typing_extensions import Literal
|
||||
@@ -13,7 +14,7 @@ class _Database(MutableMapping[_KeyType, bytes]):
|
||||
def __iter__(self) -> Iterator[bytes]: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __del__(self) -> None: ...
|
||||
def __enter__(self) -> _Database: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from types import TracebackType
|
||||
from typing import Iterator, MutableMapping, Union
|
||||
|
||||
@@ -17,7 +18,7 @@ class _Database(MutableMapping[_KeyType, bytes]):
|
||||
def __iter__(self) -> Iterator[bytes]: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __del__(self) -> None: ...
|
||||
def __enter__(self) -> _Database: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from types import TracebackType
|
||||
from typing import TypeVar, Union, overload
|
||||
|
||||
@@ -18,7 +19,7 @@ class _gdbm:
|
||||
def __setitem__(self, key: _KeyType, value: _ValueType) -> None: ...
|
||||
def __delitem__(self, key: _KeyType) -> None: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __enter__(self) -> _gdbm: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from types import TracebackType
|
||||
from typing import TypeVar, Union, overload
|
||||
|
||||
@@ -17,7 +18,7 @@ class _dbm:
|
||||
def __delitem__(self, key: _KeyType) -> None: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __del__(self) -> None: ...
|
||||
def __enter__(self) -> _dbm: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from typing import Any, Callable, Generic, Iterable, Iterator, Sequence, TypeVar, overload
|
||||
|
||||
_T = TypeVar("_T")
|
||||
@@ -8,14 +9,14 @@ def count(start: int = ..., step: int = ...) -> Iterator[int]: ... # more gener
|
||||
class cycle(Iterator[_T], Generic[_T]):
|
||||
def __init__(self, iterable: Iterable[_T]) -> None: ...
|
||||
def next(self) -> _T: ...
|
||||
def __iter__(self) -> Iterator[_T]: ...
|
||||
def __iter__(self: Self) -> Self: ...
|
||||
|
||||
def repeat(object: _T, times: int = ...) -> Iterator[_T]: ...
|
||||
|
||||
class chain(Iterator[_T], Generic[_T]):
|
||||
def __init__(self, *iterables: Iterable[_T]) -> None: ...
|
||||
def next(self) -> _T: ...
|
||||
def __iter__(self) -> Iterator[_T]: ...
|
||||
def __iter__(self: Self) -> Self: ...
|
||||
@staticmethod
|
||||
def from_iterable(iterable: Iterable[Iterable[_S]]) -> Iterator[_S]: ...
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from typing import Any, Callable, Iterable, Iterator
|
||||
|
||||
class AsyncResult:
|
||||
@@ -7,7 +8,7 @@ class AsyncResult:
|
||||
def successful(self) -> bool: ...
|
||||
|
||||
class IMapIterator(Iterator[Any]):
|
||||
def __iter__(self) -> Iterator[Any]: ...
|
||||
def __iter__(self: Self) -> Self: ...
|
||||
def next(self, timeout: float | None = ...) -> Any: ...
|
||||
|
||||
class IMapUnorderedIterator(IMapIterator): ...
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import collections
|
||||
from _typeshed import Self
|
||||
from typing import Any, Iterator
|
||||
|
||||
class Shelf(collections.MutableMapping[Any, Any]):
|
||||
@@ -14,7 +15,7 @@ class Shelf(collections.MutableMapping[Any, Any]):
|
||||
def __getitem__(self, key: Any) -> Any: ...
|
||||
def __setitem__(self, key: Any, value: Any) -> None: ...
|
||||
def __delitem__(self, key: Any) -> None: ...
|
||||
def __enter__(self) -> Shelf: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
def __del__(self) -> None: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from datetime import date, datetime, time
|
||||
from typing import Any, Callable, Generator, Iterable, Iterator, Protocol, Text, TypeVar
|
||||
|
||||
@@ -126,7 +127,7 @@ class Connection(object):
|
||||
def enable_load_extension(self, enabled: bool) -> None: ...
|
||||
def load_extension(self, path: str) -> None: ...
|
||||
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
|
||||
def __enter__(self) -> Connection: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, t: type | None, exc: BaseException | None, tb: Any | None) -> None: ...
|
||||
|
||||
class Cursor(Iterator[Any]):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import socket
|
||||
import sys
|
||||
from _typeshed import StrPath
|
||||
from _typeshed import Self, StrPath
|
||||
from typing import Any, Callable, ClassVar, Iterable, NamedTuple, Optional, Text, Union, overload
|
||||
from typing_extensions import Literal
|
||||
|
||||
@@ -213,7 +213,7 @@ class SSLSocket(socket.socket):
|
||||
class SSLContext:
|
||||
check_hostname: bool
|
||||
options: int
|
||||
def __new__(cls, protocol: int, *args: Any, **kwargs: Any) -> SSLContext: ...
|
||||
def __new__(cls: type[Self], protocol: int, *args: Any, **kwargs: Any) -> Self: ...
|
||||
@property
|
||||
def protocol(self) -> int: ...
|
||||
verify_flags: int
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import io
|
||||
from _typeshed import Self
|
||||
from types import TracebackType
|
||||
from typing import IO, Callable, Iterable, Iterator, Mapping, Text
|
||||
|
||||
@@ -103,7 +104,7 @@ class TarFile(Iterable[TarInfo]):
|
||||
errorlevel: int | None = ...,
|
||||
copybufsize: int | None = ..., # undocumented
|
||||
) -> None: ...
|
||||
def __enter__(self) -> TarFile: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from random import Random
|
||||
from thread import LockType
|
||||
from typing import IO, Any, AnyStr, Iterable, Iterator, Text, overload
|
||||
@@ -23,7 +24,7 @@ class _TemporaryFileWrapper(IO[str]):
|
||||
name: Any
|
||||
def __init__(self, file: IO[str], name: Any, delete: bool = ...) -> None: ...
|
||||
def __del__(self) -> None: ...
|
||||
def __enter__(self) -> _TemporaryFileWrapper: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, exc, value, tb) -> bool | None: ...
|
||||
def __getattr__(self, name: unicode) -> Any: ...
|
||||
def close(self) -> None: ...
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from typing import Any, Callable
|
||||
from typing_extensions import final
|
||||
|
||||
def _count() -> int: ...
|
||||
|
||||
class error(Exception): ...
|
||||
|
||||
@final
|
||||
class LockType:
|
||||
def acquire(self, waitflag: int = ...) -> bool: ...
|
||||
def acquire_lock(self, waitflag: int = ...) -> bool: ...
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import sys
|
||||
from typing import Any, NamedTuple
|
||||
from typing_extensions import final
|
||||
|
||||
_TimeTuple = tuple[int, int, int, int, int, int, int, int, int]
|
||||
|
||||
@@ -26,6 +27,7 @@ class _struct_time(NamedTuple):
|
||||
@property
|
||||
def n_unnamed_fields(self) -> int: ...
|
||||
|
||||
@final
|
||||
class struct_time(_struct_time):
|
||||
def __init__(self, o: _TimeTuple, _arg: Any = ...) -> None: ...
|
||||
def __new__(cls, o: _TimeTuple, _arg: Any = ...) -> struct_time: ...
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import datetime
|
||||
import types
|
||||
from _typeshed import Self
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from typing import Any, Callable, Iterable, Iterator, Mapping, NoReturn, Pattern, Sequence, Text, TextIO, TypeVar, Union, overload
|
||||
from typing_extensions import ParamSpec
|
||||
@@ -54,7 +55,7 @@ class _AssertRaisesBaseContext:
|
||||
|
||||
class _AssertRaisesContext(_AssertRaisesBaseContext):
|
||||
exception: Any
|
||||
def __enter__(self) -> _AssertRaisesContext: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, exc_type, exc_value, tb) -> bool: ...
|
||||
|
||||
class TestCase(Testable):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import io
|
||||
from _typeshed import StrPath
|
||||
from _typeshed import Self, StrPath
|
||||
from types import TracebackType
|
||||
from typing import IO, Any, Callable, Iterable, Pattern, Protocol, Sequence, Text, Union
|
||||
|
||||
@@ -46,7 +46,7 @@ class ZipFile:
|
||||
NameToInfo: dict[Text, ZipInfo]
|
||||
start_dir: int # undocumented
|
||||
def __init__(self, file: StrPath | IO[bytes], mode: Text = ..., compression: int = ..., allowZip64: bool = ...) -> None: ...
|
||||
def __enter__(self) -> ZipFile: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user