From eb8648ba50d7c43b1d7542143aadab016acd4a8a Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Wed, 14 Sep 2016 22:34:32 +0300 Subject: [PATCH 1/3] signatures for cast and NewType --- stdlib/3/typing.pyi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index b3500fb6881f..9629020a366d 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -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]: ... + From 39edaf9a155c2a8e8157c07581e5b795b2e806d4 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Wed, 14 Sep 2016 22:37:50 +0300 Subject: [PATCH 2/3] 2.7 too --- stdlib/2.7/typing.pyi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/2.7/typing.pyi b/stdlib/2.7/typing.pyi index e64fa2ee3035..90a22292df24 100644 --- a/stdlib/2.7/typing.pyi +++ b/stdlib/2.7/typing.pyi @@ -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]: ... + From e162d57d9c8ad93e5acdaf3c70a36c92a8c5e130 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Sat, 22 Oct 2016 21:59:39 +0300 Subject: [PATCH 3/3] remove builtinclass --- stdlib/2.7/typing.pyi | 1 - stdlib/3/typing.pyi | 1 - 2 files changed, 2 deletions(-) diff --git a/stdlib/2.7/typing.pyi b/stdlib/2.7/typing.pyi index 90a22292df24..314743c8284b 100644 --- a/stdlib/2.7/typing.pyi +++ b/stdlib/2.7/typing.pyi @@ -12,7 +12,6 @@ Generic = object() Tuple = object() Callable = object() Type = object() -builtinclass = object() _promote = object() # Type aliases diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 9629020a366d..f59df651928a 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -13,7 +13,6 @@ Generic = object() Tuple = object() Callable = object() Type = object() -builtinclass = object() _promote = object() no_type_check = object()