mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 05:24:52 +08:00
Add mypy fallback class for TypedDict methods to mypy_extensions (#2670)
This class is not defined at runtime but it's used by mypy internally to support TypedDict methods. Use NoReturn in argument types for better type safety when the related mypy plugin hook is not active.
This commit is contained in:
22
third_party/2and3/mypy_extensions.pyi
vendored
22
third_party/2and3/mypy_extensions.pyi
vendored
@@ -1,8 +1,28 @@
|
||||
from typing import Dict, Type, TypeVar, Optional, Union, Any, Generic
|
||||
import abc
|
||||
import sys
|
||||
from typing import (
|
||||
Dict, Type, TypeVar, Optional, Union, Any, Generic, Mapping, ItemsView, KeysView, ValuesView
|
||||
)
|
||||
|
||||
_T = TypeVar('_T')
|
||||
_U = TypeVar('_U')
|
||||
|
||||
# Internal mypy fallback type for all typed dicts (does not exist at runtime)
|
||||
class _TypedDict(Mapping[str, object], metaclass=abc.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: ...
|
||||
if sys.version_info < (3, 0):
|
||||
def has_key(self) -> bool: ...
|
||||
def viewitems(self) -> ItemsView[str, object]: ...
|
||||
def viewkeys(self) -> KeysView[str]: ...
|
||||
def viewvalues(self) -> ValuesView[object]: ...
|
||||
def __delitem__(self, k: NoReturn) -> None: ...
|
||||
|
||||
def TypedDict(typename: str, fields: Dict[str, Type[_T]], total: bool = ...) -> Type[dict]: ...
|
||||
|
||||
def Arg(type: _T = ..., name: Optional[str] = ...) -> _T: ...
|
||||
|
||||
Reference in New Issue
Block a user