mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-20 10:51:15 +08:00
Add signatures for cast() and NewType (#549)
(Mypy ignores these in favor of hard-coded behaviors, but the signatures here may be useful for other tools.)
This commit is contained in:
@@ -5,7 +5,6 @@ from abc import abstractmethod, ABCMeta
|
||||
# Definitions of special type checking related constructs. Their definition
|
||||
# are not used, so their value does not matter.
|
||||
|
||||
cast = object()
|
||||
overload = object()
|
||||
Any = object()
|
||||
TypeVar = object()
|
||||
@@ -15,7 +14,6 @@ Callable = object()
|
||||
Type = object()
|
||||
builtinclass = object()
|
||||
_promote = object()
|
||||
NewType = object()
|
||||
|
||||
# Type aliases
|
||||
|
||||
@@ -350,8 +348,13 @@ class Pattern(Generic[AnyStr]):
|
||||
|
||||
def get_type_hints(obj: Callable) -> dict[str, Any]: ...
|
||||
|
||||
def cast(tp: Type[_T], obj: Any) -> _T: ...
|
||||
|
||||
# Type constructors
|
||||
|
||||
# NamedTuple is special-cased in the type checker; the initializer is ignored.
|
||||
def NamedTuple(typename: str, fields: Iterable[Tuple[str, Any]], *,
|
||||
verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ...
|
||||
|
||||
def NewType(name: str, tp: Type[_T]) -> Type[_T]: ...
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ from abc import abstractmethod, ABCMeta
|
||||
# Definitions of special type checking related constructs. Their definition
|
||||
# are not used, so their value does not matter.
|
||||
|
||||
cast = object()
|
||||
overload = object()
|
||||
Any = object()
|
||||
TypeVar = object()
|
||||
@@ -17,7 +16,6 @@ Type = object()
|
||||
builtinclass = object()
|
||||
_promote = object()
|
||||
no_type_check = object()
|
||||
NewType = object()
|
||||
|
||||
# Type aliases and type constructors
|
||||
|
||||
@@ -420,8 +418,13 @@ class Pattern(Generic[AnyStr]):
|
||||
|
||||
def get_type_hints(obj: Callable) -> dict[str, Any]: ...
|
||||
|
||||
def cast(tp: Type[_T], obj: Any) -> _T: ...
|
||||
|
||||
# Type constructors
|
||||
|
||||
# NamedTuple is special-cased in the type checker; the initializer is ignored.
|
||||
def NamedTuple(typename: str, fields: Iterable[Tuple[str, Any]], *,
|
||||
verbose: bool = ..., rename: bool = ..., module: str = None) -> Type[tuple]: ...
|
||||
|
||||
def NewType(name: str, tp: Type[_T]) -> Type[_T]: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user