From b1edf4a597220404201d7c1cc435cd1c426be9fa Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Thu, 1 Sep 2016 05:20:58 +0300 Subject: [PATCH 1/5] add TypeAlias for OrderedDict --- stdlib/2.7/typing.pyi | 1 + stdlib/3/typing.pyi | 1 + 2 files changed, 2 insertions(+) diff --git a/stdlib/2.7/typing.pyi b/stdlib/2.7/typing.pyi index 5e0906e0d113..5ddec2ba3396 100644 --- a/stdlib/2.7/typing.pyi +++ b/stdlib/2.7/typing.pyi @@ -30,6 +30,7 @@ Optional = TypeAlias(object) List = TypeAlias(object) Dict = TypeAlias(object) DefaultDict = TypeAlias(object) +OrderedDict = TypeAlias(object) Set = TypeAlias(object) # Predefined type variables. diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 438d2648b615..077b50af531b 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -32,6 +32,7 @@ Optional = TypeAlias(object) List = TypeAlias(object) Dict = TypeAlias(object) DefaultDict = TypeAlias(object) +OrderedDict = TypeAlias(object) Set = TypeAlias(object) # Predefined type variables. From d0bff3356b33844f2495b28bb3d2d94deb29004c Mon Sep 17 00:00:00 2001 From: Elazar Date: Thu, 1 Sep 2016 05:28:22 +0300 Subject: [PATCH 2/5] _ --- stdlib/2.7/typing.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/2.7/typing.pyi b/stdlib/2.7/typing.pyi index 5ddec2ba3396..2d3fe539b529 100644 --- a/stdlib/2.7/typing.pyi +++ b/stdlib/2.7/typing.pyi @@ -31,6 +31,7 @@ List = TypeAlias(object) Dict = TypeAlias(object) DefaultDict = TypeAlias(object) OrderedDict = TypeAlias(object) + Set = TypeAlias(object) # Predefined type variables. From b2a729b36ec28da72cd8b1259b75a5045640ce45 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Sun, 30 Oct 2016 01:40:17 +0200 Subject: [PATCH 3/5] Dedicated TypeVar works and seems to be more suitable --- stdlib/2/__builtin__.pyi | 5 +++-- stdlib/3/builtins.pyi | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 06793fabd0b4..f10648dd141b 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -4,7 +4,7 @@ # Python 3, and stub files conform to Python 3 syntax. from typing import ( - TypeVar, Iterator, Iterable, overload, Type, + TypeVar, Iterator, Iterable, overload, Sequence, Mapping, Tuple, List, Any, Dict, Callable, Generic, Set, AbstractSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs, SupportsRound, IO, BinaryIO, Union, AnyStr, MutableSequence, MutableMapping, @@ -21,6 +21,7 @@ _T1 = TypeVar('_T1') _T2 = TypeVar('_T2') _T3 = TypeVar('_T3') _T4 = TypeVar('_T4') +_TT = TypeVar('_TT', bound='type') class staticmethod: pass # Special, only valid as a decorator. class classmethod: pass # Special, only valid as a decorator. @@ -60,7 +61,7 @@ class type: # Note: the documentation doesnt specify what the return type is, the standard # implementation seems to be returning a list. def mro(self) -> List[type]: ... - def __subclasses__(self: Type[_T]) -> List[Type[_T]]: ... + def __subclasses__(self: _TT) -> List[_TT]: ... class int(SupportsInt, SupportsFloat, SupportsAbs[int]): @overload diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 42b6e24bed18..aa25bca7d61e 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -1,7 +1,7 @@ # Stubs for builtins (Python 3) from typing import ( - TypeVar, Iterator, Iterable, overload, Type, + TypeVar, Iterator, Iterable, overload, Sequence, MutableSequence, Mapping, MutableMapping, Tuple, List, Any, Dict, Callable, Generic, Set, AbstractSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsBytes, SupportsAbs, SupportsRound, IO, Union, ItemsView, KeysView, ValuesView, ByteString, Optional @@ -22,6 +22,7 @@ _T1 = TypeVar('_T1') _T2 = TypeVar('_T2') _T3 = TypeVar('_T3') _T4 = TypeVar('_T4') +_TT = TypeVar('_TT', bound='type') class staticmethod: pass # Special, only valid as a decorator. class classmethod: pass # Special, only valid as a decorator. @@ -57,7 +58,7 @@ class type: @overload def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ... def __call__(self, *args: Any, **kwds: Any) -> Any: ... - def __subclasses__(self: Type[_T]) -> List[Type[_T]]: ... + def __subclasses__(self: _TT) -> List[_TT]: ... # Note: the documentation doesnt specify what the return type is, the standard # implementation seems to be returning a list. def mro(self) -> List[type]: ... From 7cfccda428e3fbc46c9e6bbd99fb16c674136074 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Sun, 30 Oct 2016 01:44:35 +0200 Subject: [PATCH 4/5] revert old change --- stdlib/2/typing.pyi | 1 - stdlib/3/typing.pyi | 1 - 2 files changed, 2 deletions(-) diff --git a/stdlib/2/typing.pyi b/stdlib/2/typing.pyi index 0956f570720c..a25b9f5edce9 100644 --- a/stdlib/2/typing.pyi +++ b/stdlib/2/typing.pyi @@ -26,7 +26,6 @@ Optional = TypeAlias(object) List = TypeAlias(object) Dict = TypeAlias(object) DefaultDict = TypeAlias(object) -OrderedDict = TypeAlias(object) Set = TypeAlias(object) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index afb9d48f153b..f59df651928a 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -28,7 +28,6 @@ Optional = TypeAlias(object) List = TypeAlias(object) Dict = TypeAlias(object) DefaultDict = TypeAlias(object) -OrderedDict = TypeAlias(object) Set = TypeAlias(object) # Predefined type variables. From c3e38cca998c065d305a22aa806bb68a8d37396d Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Sun, 30 Oct 2016 01:50:33 +0200 Subject: [PATCH 5/5] kill blank --- stdlib/2/typing.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/2/typing.pyi b/stdlib/2/typing.pyi index a25b9f5edce9..314743c8284b 100644 --- a/stdlib/2/typing.pyi +++ b/stdlib/2/typing.pyi @@ -26,7 +26,6 @@ Optional = TypeAlias(object) List = TypeAlias(object) Dict = TypeAlias(object) DefaultDict = TypeAlias(object) - Set = TypeAlias(object) # Predefined type variables.