Add special methods for object#774
Conversation
JukkaL
left a comment
There was a problem hiding this comment.
Some of these didn't seem right when I tried them with object() instances. How did you come up with this set of methods?
stdlib/3/builtins.pyi
Outdated
| def __setattr__(self, name: str, value: Any) -> None: ... | ||
| def __eq__(self, o: object) -> bool: ... | ||
| def __ne__(self, o: object) -> bool: ... | ||
| def __lt__(self, o: object) -> bool: ... |
There was a problem hiding this comment.
These 4 definitions will break mypy. It's best to leave them out and potentially file a separate issue about these.
stdlib/3/builtins.pyi
Outdated
| def __str__(self) -> str: ... | ||
| def __repr__(self) -> str: ... | ||
| def __hash__(self) -> int: ... | ||
| def __del__(self) -> None: ... |
There was a problem hiding this comment.
These don't seem to exist in Python 3.5.1: __del__, __bytes__, __bool__, __getattr__, __get__, __set__.
stdlib/2/__builtin__.pyi
Outdated
| def __str__(self) -> str: ... | ||
| def __repr__(self) -> str: ... | ||
| def __hash__(self) -> int: ... | ||
| def __del__(self) -> None: ... |
There was a problem hiding this comment.
This doesn't seem to exist.
stdlib/2/__builtin__.pyi
Outdated
|
|
||
| def __get__(self, instance: Optional[object], owner: Type) -> Any: ... | ||
| def __set__(self, instance: object, value: Any) -> None: ... | ||
| def __delete__(self, instance: object) -> None: ... |
There was a problem hiding this comment.
These don't seem to exist: __get__, __set__ and __delete__
|
If you looked up these from documentation, you should be aware of that (Python) documentation is not to be trusted as a source of truth when creating stubs -- docs tend to have too many inaccuracies and outright errors. |
|
Yeah I tried looking at the CPython code, but I didn't quite get what is happening there. I checked for existence of the methods with the interpreter and removed the ones which failed. The 4 comparison operators are taken out. A pull request for mypy, which would allow defining them, is here: python/mypy#2584. |
63ba0ab to
7853c26
Compare
|
I've added Though maybe it should have the argument type There are also some redundant definitions of |
|
@JukkaL can you approve and/or merge? |
|
Thanks for the updates!
|
Adds special methods for
objectas per #773.3.6 also added
__set_name__, but I'm uncertain if simply creating the directorystdlib/3.6would suffice to add 3.6-specific type hints.There are also still missing special methods, like
__prepare__: I'm just confused to which class they belong.