mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-02 01:23:24 +08:00
Sync recent typing and typing_extensions updates (#3070)
This includes two things to sync up with recent runtime updates: * Move `Final`, `@final`, `Literal`, and `TypedDict` to `typing` (`typing_extensions` still defines or re-exports them) * Rename `@typing.runtime` to `@typing.runtime_checkable`, while keeping `@runtime` as a backwards-compatible alias in `typing_extensions`.
This commit is contained in:
@@ -22,6 +22,12 @@ Protocol: _SpecialForm = ...
|
||||
Callable: _SpecialForm = ...
|
||||
Type: _SpecialForm = ...
|
||||
ClassVar: _SpecialForm = ...
|
||||
Final: _SpecialForm = ...
|
||||
_F = TypeVar('_F', bound=Callable[..., Any])
|
||||
def final(f: _F) -> _F: ...
|
||||
Literal: _SpecialForm = ...
|
||||
# TypedDict is a (non-subscriptable) special form.
|
||||
TypedDict: object = ...
|
||||
|
||||
class GenericMeta(type): ...
|
||||
|
||||
@@ -65,39 +71,39 @@ _T_contra = TypeVar('_T_contra', contravariant=True) # Ditto contravariant.
|
||||
_TC = TypeVar('_TC', bound=Type[object])
|
||||
_C = TypeVar("_C", bound=Callable)
|
||||
|
||||
def runtime(cls: _TC) -> _TC: ...
|
||||
def runtime_checkable(cls: _TC) -> _TC: ...
|
||||
|
||||
@runtime
|
||||
@runtime_checkable
|
||||
class SupportsInt(Protocol, metaclass=ABCMeta):
|
||||
@abstractmethod
|
||||
def __int__(self) -> int: ...
|
||||
|
||||
@runtime
|
||||
@runtime_checkable
|
||||
class SupportsFloat(Protocol, metaclass=ABCMeta):
|
||||
@abstractmethod
|
||||
def __float__(self) -> float: ...
|
||||
|
||||
@runtime
|
||||
@runtime_checkable
|
||||
class SupportsComplex(Protocol, metaclass=ABCMeta):
|
||||
@abstractmethod
|
||||
def __complex__(self) -> complex: ...
|
||||
|
||||
@runtime
|
||||
@runtime_checkable
|
||||
class SupportsAbs(Protocol[_T_co]):
|
||||
@abstractmethod
|
||||
def __abs__(self) -> _T_co: ...
|
||||
|
||||
@runtime
|
||||
@runtime_checkable
|
||||
class Reversible(Protocol[_T_co]):
|
||||
@abstractmethod
|
||||
def __reversed__(self) -> Iterator[_T_co]: ...
|
||||
|
||||
@runtime
|
||||
@runtime_checkable
|
||||
class Sized(Protocol, metaclass=ABCMeta):
|
||||
@abstractmethod
|
||||
def __len__(self) -> int: ...
|
||||
|
||||
@runtime
|
||||
@runtime_checkable
|
||||
class Hashable(Protocol, metaclass=ABCMeta):
|
||||
# TODO: This is special, in that a subclass of a hashable class may not be hashable
|
||||
# (for example, list vs. object). It's not obvious how to represent this. This class
|
||||
@@ -105,12 +111,12 @@ class Hashable(Protocol, metaclass=ABCMeta):
|
||||
@abstractmethod
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
@runtime
|
||||
@runtime_checkable
|
||||
class Iterable(Protocol[_T_co]):
|
||||
@abstractmethod
|
||||
def __iter__(self) -> Iterator[_T_co]: ...
|
||||
|
||||
@runtime
|
||||
@runtime_checkable
|
||||
class Iterator(Iterable[_T_co], Protocol[_T_co]):
|
||||
@abstractmethod
|
||||
def next(self) -> _T_co: ...
|
||||
@@ -135,7 +141,7 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]):
|
||||
@property
|
||||
def gi_running(self) -> bool: ...
|
||||
|
||||
@runtime
|
||||
@runtime_checkable
|
||||
class Container(Protocol[_T_co]):
|
||||
@abstractmethod
|
||||
def __contains__(self, x: object) -> bool: ...
|
||||
@@ -234,7 +240,7 @@ class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):
|
||||
def __contains__(self, o: object) -> bool: ...
|
||||
def __iter__(self) -> Iterator[_VT_co]: ...
|
||||
|
||||
@runtime
|
||||
@runtime_checkable
|
||||
class ContextManager(Protocol[_T_co]):
|
||||
def __enter__(self) -> _T_co: ...
|
||||
def __exit__(self, __exc_type: Optional[Type[BaseException]],
|
||||
@@ -462,6 +468,21 @@ class NamedTuple(tuple):
|
||||
def _asdict(self) -> dict: ...
|
||||
def _replace(self: _T, **kwargs: Any) -> _T: ...
|
||||
|
||||
# Internal mypy fallback type for all typed dicts (does not exist at runtime)
|
||||
class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
|
||||
def copy(self: _T) -> _T: ...
|
||||
# Using NoReturn so that only calls using mypy plugin hook that specialize the signature
|
||||
# can go through.
|
||||
def setdefault(self, k: NoReturn, default: object) -> object: ...
|
||||
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
|
||||
def pop(self, k: NoReturn, default: _T = ...) -> object: ...
|
||||
def update(self: _T, __m: _T) -> None: ...
|
||||
def has_key(self, k: str) -> bool: ...
|
||||
def viewitems(self) -> ItemsView[str, object]: ...
|
||||
def viewkeys(self) -> KeysView[str]: ...
|
||||
def viewvalues(self) -> ValuesView[object]: ...
|
||||
def __delitem__(self, k: NoReturn) -> None: ...
|
||||
|
||||
def NewType(name: str, tp: Type[_T]) -> Type[_T]: ...
|
||||
|
||||
# This itself is only available during type checking
|
||||
|
||||
Reference in New Issue
Block a user