From 45f63936687570970ad547e8759ab982d69ae506 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Fri, 7 Jul 2017 16:19:57 -0700 Subject: [PATCH 1/6] Add stub for typing_extensions module --- third_party/2and3/typing_extensions.pyi | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 third_party/2and3/typing_extensions.pyi diff --git a/third_party/2and3/typing_extensions.pyi b/third_party/2and3/typing_extensions.pyi new file mode 100644 index 000000000000..9bb74f6875e4 --- /dev/null +++ b/third_party/2and3/typing_extensions.pyi @@ -0,0 +1,32 @@ +import sys +import typing +from typing import ( + ClassVar, ContextManager, Counter, DefaultDict, Deque, + NewType, overload, Text, TYPE_CHECKING, +) + +if sys.version_info >= (3, 3): + from typing import ChainMap + +if sys.version_info >= (3, 5): + from typing import ( + AsyncIterable, AsyncIterator, AsyncContextManager, Coroutine, + ) + +if sys.version_info >= (3, 6): + from typing import AsyncGenerator + +if sys.version_info >= (3, 6): + from typing import Collection +else: + _T_co = typing.TypeVar('_T_co', covariant=True) + class Collection(typing.Sized, + typing.Iterable[_T_co], + typing.Container[_T_co], + typing.Generic[_T_co]): + ... + +# Return type that indicates a function does not return. +# This type is equivalent to the None type, but the no-op Union is necessary to +# distinguish the None type from the None value. +NoReturn = typing.Union[None] From b9326df68ca203fbafad8550c210c09947422130 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Fri, 7 Jul 2017 22:09:29 -0700 Subject: [PATCH 2/6] Remove Collections backport See latest comment in https://github.com/python/typing/pull/443 for justification. --- third_party/2and3/typing_extensions.pyi | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/third_party/2and3/typing_extensions.pyi b/third_party/2and3/typing_extensions.pyi index 9bb74f6875e4..6813630ce61b 100644 --- a/third_party/2and3/typing_extensions.pyi +++ b/third_party/2and3/typing_extensions.pyi @@ -16,16 +16,6 @@ if sys.version_info >= (3, 5): if sys.version_info >= (3, 6): from typing import AsyncGenerator -if sys.version_info >= (3, 6): - from typing import Collection -else: - _T_co = typing.TypeVar('_T_co', covariant=True) - class Collection(typing.Sized, - typing.Iterable[_T_co], - typing.Container[_T_co], - typing.Generic[_T_co]): - ... - # Return type that indicates a function does not return. # This type is equivalent to the None type, but the no-op Union is necessary to # distinguish the None type from the None value. From 07a7be41cffba555b6c71a75679aac2c9aa35968 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Sat, 8 Jul 2017 11:36:04 -0700 Subject: [PATCH 3/6] Make module re-exports compliant with PEP 484 --- third_party/2and3/typing_extensions.pyi | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/third_party/2and3/typing_extensions.pyi b/third_party/2and3/typing_extensions.pyi index 6813630ce61b..2ced07df96f6 100644 --- a/third_party/2and3/typing_extensions.pyi +++ b/third_party/2and3/typing_extensions.pyi @@ -1,20 +1,26 @@ import sys import typing -from typing import ( - ClassVar, ContextManager, Counter, DefaultDict, Deque, - NewType, overload, Text, TYPE_CHECKING, -) +from typing import ClassVar as ClassVar +from typing import ContextManager as ContextManager +from typing import Counter as Counter +from typing import DefaultDict as DefaultDict +from typing import Deque as Deque +from typing import NewType as NewType +from typing import overload as overload +from typing import Text as Text +from typing import TYPE_CHECKING as TYPE_CHECKING if sys.version_info >= (3, 3): - from typing import ChainMap + from typing import ChainMap as ChainMap if sys.version_info >= (3, 5): - from typing import ( - AsyncIterable, AsyncIterator, AsyncContextManager, Coroutine, - ) + from typing import AsyncIterable as AsyncIterable + from typing import AsyncIterator as AsyncIterator + from typing import AsyncContextManager as AsyncContextManager + from typing import Coroutine as Coroutine if sys.version_info >= (3, 6): - from typing import AsyncGenerator + from typing import AsyncGenerator as AsyncGenerator # Return type that indicates a function does not return. # This type is equivalent to the None type, but the no-op Union is necessary to From ccb20c09b39a51b20f16839058fb311f73695b77 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Thu, 20 Jul 2017 08:32:10 -0700 Subject: [PATCH 4/6] Add missing imports and enhance NoReturn comment Changes made: - Add missing `Type` re-export - Add missing `Awaitable` re-export - Add TODO note to `NoReturn`. --- third_party/2and3/typing_extensions.pyi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/third_party/2and3/typing_extensions.pyi b/third_party/2and3/typing_extensions.pyi index 2ced07df96f6..4561a4e05637 100644 --- a/third_party/2and3/typing_extensions.pyi +++ b/third_party/2and3/typing_extensions.pyi @@ -8,6 +8,7 @@ from typing import Deque as Deque from typing import NewType as NewType from typing import overload as overload from typing import Text as Text +from typing import Type as Type from typing import TYPE_CHECKING as TYPE_CHECKING if sys.version_info >= (3, 3): @@ -17,6 +18,7 @@ if sys.version_info >= (3, 5): from typing import AsyncIterable as AsyncIterable from typing import AsyncIterator as AsyncIterator from typing import AsyncContextManager as AsyncContextManager + from typing import Awaitable as Awaitable from typing import Coroutine as Coroutine if sys.version_info >= (3, 6): @@ -25,4 +27,7 @@ if sys.version_info >= (3, 6): # Return type that indicates a function does not return. # This type is equivalent to the None type, but the no-op Union is necessary to # distinguish the None type from the None value. +# +# TODO: Replace with direct import from typing once NoReturn is added to +# typing.pyi. NoReturn = typing.Union[None] From ad652378581c4ca035cfdef8940b4a148778e4fe Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Thu, 20 Jul 2017 23:07:48 -0700 Subject: [PATCH 5/6] Re-export NoReturn from typing.pyi --- third_party/2and3/typing_extensions.pyi | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/third_party/2and3/typing_extensions.pyi b/third_party/2and3/typing_extensions.pyi index 4561a4e05637..e27f94251169 100644 --- a/third_party/2and3/typing_extensions.pyi +++ b/third_party/2and3/typing_extensions.pyi @@ -6,6 +6,7 @@ from typing import Counter as Counter from typing import DefaultDict as DefaultDict from typing import Deque as Deque from typing import NewType as NewType +from typing import NoReturn as NoReturn from typing import overload as overload from typing import Text as Text from typing import Type as Type @@ -24,10 +25,3 @@ if sys.version_info >= (3, 5): if sys.version_info >= (3, 6): from typing import AsyncGenerator as AsyncGenerator -# Return type that indicates a function does not return. -# This type is equivalent to the None type, but the no-op Union is necessary to -# distinguish the None type from the None value. -# -# TODO: Replace with direct import from typing once NoReturn is added to -# typing.pyi. -NoReturn = typing.Union[None] From 219cf5c03d494539865ef881c5040a6910e7d4f8 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Thu, 20 Jul 2017 23:14:21 -0700 Subject: [PATCH 6/6] Fix flake8 error --- third_party/2and3/typing_extensions.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/third_party/2and3/typing_extensions.pyi b/third_party/2and3/typing_extensions.pyi index e27f94251169..67d671ba1074 100644 --- a/third_party/2and3/typing_extensions.pyi +++ b/third_party/2and3/typing_extensions.pyi @@ -24,4 +24,3 @@ if sys.version_info >= (3, 5): if sys.version_info >= (3, 6): from typing import AsyncGenerator as AsyncGenerator -