From f4dad9b5093f9bfec9518907b80beeb581bba32e Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 15 Aug 2017 13:14:17 +0200 Subject: [PATCH] make __class__ refer to the current object's class Fixes python/mypy#3061 --- stdlib/2/__builtin__.pyi | 7 +++++-- stdlib/2/types.pyi | 1 - stdlib/3/builtins.pyi | 6 ++++-- stdlib/3/unittest/mock.pyi | 1 - 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index b781292ec2b6..3d9a6d450a22 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -10,7 +10,7 @@ from typing import ( SupportsRound, IO, BinaryIO, Union, AnyStr, MutableSequence, MutableMapping, MutableSet, ItemsView, KeysView, ValuesView, Optional, Container, Type ) -from abc import abstractmethod, ABCMeta +from abc import ABCMeta from mypy_extensions import NoReturn _T = TypeVar('_T') @@ -27,10 +27,13 @@ _TT = TypeVar('_TT', bound='type') class object: __doc__ = ... # type: Optional[str] - __class__ = ... # type: type __slots__ = ... # type: Optional[Union[str, unicode, Iterable[Union[str, unicode]]]] __module__ = ... # type: str + @property + def __class__(self: _T) -> Type[_T]: ... + @__class__.setter + def __class__(self, __type: Type[object]) -> None: ... def __init__(self) -> None: ... def __new__(cls) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... diff --git a/stdlib/2/types.pyi b/stdlib/2/types.pyi index 87380b32478d..43de3ee57f63 100644 --- a/stdlib/2/types.pyi +++ b/stdlib/2/types.pyi @@ -90,7 +90,6 @@ class UnboundMethodType: class InstanceType: __doc__ = ... # type: Optional[str] - __class__ = ... # type: type __module__ = ... # type: Any MethodType = UnboundMethodType diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 495217d6847f..ed545cef80ea 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -7,7 +7,6 @@ from typing import ( SupportsBytes, SupportsAbs, SupportsRound, IO, Union, ItemsView, KeysView, ValuesView, ByteString, Optional, AnyStr, Type, ) -from abc import abstractmethod, ABCMeta from types import TracebackType import sys from mypy_extensions import NoReturn @@ -29,13 +28,16 @@ _TT = TypeVar('_TT', bound='type') class object: __doc__ = ... # type: Optional[str] - __class__ = ... # type: type __dict__ = ... # type: Dict[str, Any] __slots__ = ... # type: Optional[Union[str, Iterable[str]]] __module__ = ... # type: str if sys.version_info >= (3, 6): __annotations__ = ... # type: Dict[str, Any] + @property + def __class__(self: _T) -> Type[_T]: ... + @__class__.setter + def __class__(self, __type: Type[object]) -> None: ... def __init__(self) -> None: ... def __new__(cls) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... diff --git a/stdlib/3/unittest/mock.pyi b/stdlib/3/unittest/mock.pyi index 4c78a0f83d7b..1f026d12d3db 100644 --- a/stdlib/3/unittest/mock.pyi +++ b/stdlib/3/unittest/mock.pyi @@ -42,7 +42,6 @@ if sys.version_info >= (3, 3): def attach_mock(self, mock: Any, attribute: Any) -> Any: ... def mock_add_spec(self, spec: Any, spec_set: Any = False) -> Any: ... return_value = ... # type: Any - __class__ = ... # type: type called = ... # type: Any call_count = ... # type: Any call_args = ... # type: Any