Skip to content

Commit 58221cf

Browse files
CraftSpiderJelleZijlstra
authored andcommitted
Add types and functions in types.py that are new in 3.7 (#3066)
* Add types and functions in types.py that are new in 3.7 * Update `resolve_bases` to accept any iterable of objects, and the same for `new_class` if the version is at least 3.7 * Add comparison overrides implemented by MethodWrapperType * Fix mypy error due to over-constrained `__eq__`
1 parent 1763f51 commit 58221cf

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

stdlib/3/types.pyi

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
from typing import (
88
Any, Awaitable, Callable, Dict, Generic, Iterator, Mapping, Optional, Tuple, TypeVar,
9-
Union, overload, Type
9+
Union, overload, Type, Iterable
1010
)
1111

1212
# ModuleType is exported from this module, but for circular import
@@ -156,6 +156,38 @@ class BuiltinFunctionType:
156156
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
157157
BuiltinMethodType = BuiltinFunctionType
158158

159+
if sys.version_info >= (3, 7):
160+
class WrapperDescriptorType:
161+
__name__: str
162+
__qualname__: str
163+
__objclass__: type
164+
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
165+
def __get__(self, obj: Any, type: type = ...) -> Any: ...
166+
167+
class MethodWrapperType:
168+
__self__: object
169+
__name__: str
170+
__qualname__: str
171+
__objclass__: type
172+
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
173+
def __eq__(self, other: Any) -> bool: ...
174+
def __ne__(self, other: Any) -> bool: ...
175+
176+
class MethodDescriptorType:
177+
__name__: str
178+
__qualname__: str
179+
__objclass__: type
180+
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
181+
def __get__(self, obj: Any, type: type = ...) -> Any: ...
182+
183+
class ClassMethodDescriptorType:
184+
__name__: str
185+
__qualname__: str
186+
__objclass__: type
187+
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
188+
def __get__(self, obj: Any, type: type = ...) -> Any: ...
189+
190+
159191
class TracebackType:
160192
if sys.version_info >= (3, 7):
161193
def __init__(self, tb_next: Optional[TracebackType], tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> None: ...
@@ -199,7 +231,11 @@ class MemberDescriptorType:
199231
def __set__(self, obj: Any) -> None: ...
200232
def __delete__(self, obj: Any) -> None: ...
201233

202-
def new_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ...
234+
if sys.version_info >= (3, 7):
235+
def new_class(name: str, bases: Iterable[object] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ...
236+
def resolve_bases(bases: Iterable[object]) -> Tuple[Any, ...]: ...
237+
else:
238+
def new_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ...
203239
def prepare_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ...) -> Tuple[type, Dict[str, Any], Dict[str, Any]]: ...
204240

205241
# Actually a different type, but `property` is special and we want that too.

0 commit comments

Comments
 (0)