Skip to content

Commit 1a164b6

Browse files
JelleZijlstramatthiaskramm
authored andcommitted
make __class__ refer to the current object's class (#1549)
Fixes python/mypy#3061
1 parent d389ef3 commit 1a164b6

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

stdlib/2/__builtin__.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ from typing import (
1010
SupportsRound, IO, BinaryIO, Union, AnyStr, MutableSequence, MutableMapping,
1111
MutableSet, ItemsView, KeysView, ValuesView, Optional, Container, Type
1212
)
13-
from abc import abstractmethod, ABCMeta
13+
from abc import ABCMeta
1414
from mypy_extensions import NoReturn
1515

1616
_T = TypeVar('_T')
@@ -27,10 +27,13 @@ _TT = TypeVar('_TT', bound='type')
2727

2828
class object:
2929
__doc__ = ... # type: Optional[str]
30-
__class__ = ... # type: type
3130
__slots__ = ... # type: Optional[Union[str, unicode, Iterable[Union[str, unicode]]]]
3231
__module__ = ... # type: str
3332

33+
@property
34+
def __class__(self: _T) -> Type[_T]: ...
35+
@__class__.setter
36+
def __class__(self, __type: Type[object]) -> None: ...
3437
def __init__(self) -> None: ...
3538
def __new__(cls) -> Any: ...
3639
def __setattr__(self, name: str, value: Any) -> None: ...

stdlib/2/types.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class UnboundMethodType:
9090

9191
class InstanceType:
9292
__doc__ = ... # type: Optional[str]
93-
__class__ = ... # type: type
9493
__module__ = ... # type: Any
9594

9695
MethodType = UnboundMethodType

stdlib/3/builtins.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ _TT = TypeVar('_TT', bound='type')
2929

3030
class object:
3131
__doc__ = ... # type: Optional[str]
32-
__class__ = ... # type: type
3332
__dict__ = ... # type: Dict[str, Any]
3433
__slots__ = ... # type: Optional[Union[str, Iterable[str]]]
3534
__module__ = ... # type: str
3635
if sys.version_info >= (3, 6):
3736
__annotations__ = ... # type: Dict[str, Any]
3837

38+
@property
39+
def __class__(self: _T) -> Type[_T]: ...
40+
@__class__.setter
41+
def __class__(self, __type: Type[object]) -> None: ...
3942
def __init__(self) -> None: ...
4043
def __new__(cls) -> Any: ...
4144
def __setattr__(self, name: str, value: Any) -> None: ...

stdlib/3/unittest/mock.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ if sys.version_info >= (3, 3):
4242
def attach_mock(self, mock: Any, attribute: Any) -> Any: ...
4343
def mock_add_spec(self, spec: Any, spec_set: Any = False) -> Any: ...
4444
return_value = ... # type: Any
45-
__class__ = ... # type: type
4645
called = ... # type: Any
4746
call_count = ... # type: Any
4847
call_args = ... # type: Any

0 commit comments

Comments
 (0)