-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Corrected special attributes present in object or its direct inheritors #874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2beebff
7514947
3c3b402
706c32a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,26 +30,27 @@ class classmethod: pass # Special, only valid as a decorator. | |
class object: | ||
__doc__ = ... # type: Optional[str] | ||
__class__ = ... # type: type | ||
__dict__ = ... # type: Dict[str, Any] | ||
__slots__ = ... # type: Optional[Union[str, unicode, Iterable[Union[str, unicode]]]] | ||
__module__ = ... # type: Any | ||
|
||
def __init__(self) -> None: ... | ||
def __new__(cls) -> Any: ... | ||
def __setattr__(self, name: str, value: Any) -> None: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange you're deleting these, because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's true for
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good catch. Looks like a Python 2/3 compatibility issues -- in Python 3 they exist:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, while the methods may not exist, the operations from which they are typically used (== and !=) do work on objects. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (And I just confirmed that mypy fails simple correct code like this: class A: pass
A() == A() with the error
|
||
def __eq__(self, o: object) -> bool: ... | ||
def __ne__(self, o: object) -> bool: ... | ||
def __str__(self) -> str: ... | ||
def __repr__(self) -> str: ... | ||
def __hash__(self) -> int: ... | ||
def __format__(self, format_spec: str) -> str: ... | ||
def __getattribute__(self, name: str) -> Any: ... | ||
def __delattr__(self, name: str) -> None: ... | ||
def __sizeof__(self) -> int: ... | ||
def __reduce__(self) -> Union[str, unicode, tuple]: ... | ||
def __reduce_ex__(self, protocol: int) -> Union[str, unicode, tuple]: ... | ||
|
||
class type(object): | ||
__bases__ = ... # type: Tuple[type, ...] | ||
__name__ = ... # type: str | ||
__module__ = ... # type: str | ||
__dict__ = ... # type: Dict[unicode, Any] | ||
|
||
@overload | ||
def __init__(self, o: object) -> None: ... | ||
|
@@ -482,6 +483,8 @@ class tuple(Sequence[_T_co], Generic[_T_co]): | |
def __le__(self, x: Tuple[_T_co, ...]) -> bool: ... | ||
def __gt__(self, x: Tuple[_T_co, ...]) -> bool: ... | ||
def __ge__(self, x: Tuple[_T_co, ...]) -> bool: ... | ||
def __eq__(self, x: Tuple[_T_co, ...]) -> bool: ... | ||
def __ne__(self, x: Tuple[_T_co, ...]) -> bool: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also not strictly true -- you can write However, there's discussion in python/mypy#1271, so I'm not sure what to do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this issue affects other type checkers as well, not just mypy, I created a typing issue where we can discuss this: python/typing#378 |
||
def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... | ||
def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... | ||
def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... | ||
|
@@ -653,12 +656,11 @@ class xrange(Sized, Iterable[int], Reversible[int]): | |
def __getitem__(self, i: int) -> int: ... | ||
def __reversed__(self) -> Iterator[int]: ... | ||
|
||
class module: | ||
class module(object): | ||
__name__ = ... # type: str | ||
__file__ = ... # type: str | ||
__dict__ = ... # type: Dict[unicode, Any] | ||
|
||
class property: | ||
class property(object): | ||
def __init__(self, fget: Callable[[Any], Any] = None, | ||
fset: Callable[[Any, Any], None] = None, | ||
fdel: Callable[[Any], None] = None, doc: str = None) -> None: ... | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really correct --
object
itself doesn't have__dict__
and neither do classes using__slots__
.