From 5a969327e7742eef38a4e4d4c9a8997befc8093a Mon Sep 17 00:00:00 2001 From: CraftSpider Date: Mon, 17 Jun 2019 00:14:36 -0400 Subject: [PATCH 1/4] Add types and functions in types.py that are new in 3.7 --- stdlib/3/types.pyi | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 73b88899c53f..393dd929ba39 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -156,6 +156,36 @@ class BuiltinFunctionType: def __call__(self, *args: Any, **kwargs: Any) -> Any: ... BuiltinMethodType = BuiltinFunctionType +if sys.version_info >= (3, 7): + class WrapperDescriptorType: + __name__: str + __qualname__: str + __objclass__: type + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, obj: Any, type: type = ...) -> Any: ... + + class MethodWrapperType: + __self__: object + __name__: str + __qualname__: str + __objclass__: type + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + + class MethodDescriptorType: + __name__: str + __qualname__: str + __objclass__: type + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, obj: Any, type: type = ...) -> Any: ... + + class ClassMethodDescriptorType: + __name__: str + __qualname__: str + __objclass__: type + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, obj: Any, type: type = ...) -> Any: ... + + class TracebackType: if sys.version_info >= (3, 7): def __init__(self, tb_next: Optional[TracebackType], tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> None: ... @@ -200,6 +230,8 @@ class MemberDescriptorType: def __delete__(self, obj: Any) -> None: ... def new_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ... +if sys.version_info >= (3, 7): + def resolve_bases(bases: Tuple[type, ...]) -> Tuple[type, ...]: ... def prepare_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ...) -> Tuple[type, Dict[str, Any], Dict[str, Any]]: ... # Actually a different type, but `property` is special and we want that too. From b7aa81b50e34b383bbe11a47819b424824836295 Mon Sep 17 00:00:00 2001 From: CraftSpider Date: Mon, 17 Jun 2019 15:43:10 -0400 Subject: [PATCH 2/4] Update `resolve_bases` to accept any iterable of objects, and the same for `new_class` if the version is at least 3.7 --- stdlib/3/types.pyi | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 393dd929ba39..1b1f5b799903 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -6,7 +6,7 @@ import sys from typing import ( Any, Awaitable, Callable, Dict, Generic, Iterator, Mapping, Optional, Tuple, TypeVar, - Union, overload, Type + Union, overload, Type, Iterable ) # ModuleType is exported from this module, but for circular import @@ -229,9 +229,12 @@ class MemberDescriptorType: def __set__(self, obj: Any) -> None: ... def __delete__(self, obj: Any) -> None: ... -def new_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ... + if sys.version_info >= (3, 7): - def resolve_bases(bases: Tuple[type, ...]) -> Tuple[type, ...]: ... + def new_class(name: str, bases: Iterable[object] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ... + def resolve_bases(bases: Iterable[object]) -> Tuple[Any, ...]: ... +else: + def new_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ... def prepare_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ...) -> Tuple[type, Dict[str, Any], Dict[str, Any]]: ... # Actually a different type, but `property` is special and we want that too. From 56eb00ba438a8640e2789031ace2fae47ed9f3b3 Mon Sep 17 00:00:00 2001 From: CraftSpider Date: Wed, 19 Jun 2019 15:29:21 -0400 Subject: [PATCH 3/4] Add comparison overrides implemented by MethodWrapperType --- stdlib/3/types.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 1b1f5b799903..24f5db72749e 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -170,6 +170,8 @@ if sys.version_info >= (3, 7): __qualname__: str __objclass__: type def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __eq__(self, other: 'MethodWrapperType') -> bool: ... + def __ne__(self, other: 'MethodWrapperType') -> bool: ... class MethodDescriptorType: __name__: str @@ -229,7 +231,6 @@ class MemberDescriptorType: def __set__(self, obj: Any) -> None: ... def __delete__(self, obj: Any) -> None: ... - if sys.version_info >= (3, 7): def new_class(name: str, bases: Iterable[object] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ... def resolve_bases(bases: Iterable[object]) -> Tuple[Any, ...]: ... From 9127c4c3fdf061066cdab24ed9eef7fcf2578829 Mon Sep 17 00:00:00 2001 From: CraftSpider Date: Wed, 19 Jun 2019 17:26:13 -0400 Subject: [PATCH 4/4] Fix mypy error due to over-constrained `__eq__` --- stdlib/3/types.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 24f5db72749e..5d0acc7dd24c 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -170,8 +170,8 @@ if sys.version_info >= (3, 7): __qualname__: str __objclass__: type def __call__(self, *args: Any, **kwargs: Any) -> Any: ... - def __eq__(self, other: 'MethodWrapperType') -> bool: ... - def __ne__(self, other: 'MethodWrapperType') -> bool: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... class MethodDescriptorType: __name__: str