Uh oh!
There was an error while loading. Please reload this page.
Corrected special attributes present in object or its direct inheritors - #874
Corrected special attributes present in object or its direct inheritors#874vlasovskikh wants to merge 4 commits into
Conversation
object itself doesn't have __dict__ and __slots__, but all its inheritors do have either __dict__ or __slots__.
gvanrossum
left a comment
There was a problem hiding this comment.
Maybe you can separate the non-controversial things out of this so we can merge those separately?
(Also, I realize that PyCharm's needs for typeshed are different from mypy's. Maybe we need to add some way to differentiate, similar to checks for sys.version_info and sys.platform? If you like that idea we should probably discuss this in the typing repo first.)
| class object: | ||
| __doc__ = ... # type: Optional[str] | ||
| __class__ = ... # type: type | ||
| __dict__ = ... # type: Dict[str, Any] |
There was a problem hiding this comment.
This isn't really correct -- object itself doesn't have __dict__ and neither do classes using __slots__.
| def __new__(cls) -> Any: ... | ||
| def __setattr__(self, name: str, value: Any) -> None: ... | ||
| def __eq__(self, o: object) -> bool: ... | ||
| def __ne__(self, o: object) -> bool: ... |
There was a problem hiding this comment.
Strange you're deleting these, because objectdoes have __eq__ and __ne__.
There was a problem hiding this comment.
It's true for type objects like object class, but as for object() instances I'm not sure about it:
>>> object().__eq__
Traceback (most recent call last):
...
AttributeError: 'object' object has no attribute '__eq__'
>>> object().__ne__
Traceback (most recent call last):
...
AttributeError: 'object' object has no attribute '__ne__'
There was a problem hiding this comment.
Ah, good catch. Looks like a Python 2/3 compatibility issues -- in Python 3 they exist:
>>> object().__eq__
<method-wrapper '__eq__' of object object at 0x10062e110>
There was a problem hiding this comment.
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.
(And I just confirmed that mypy fails simple correct code like this:
classA: passA() ==A()with the error
__tmp__.py:2: error: Unsupported left operand type for == ("A")
| 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.
This is also not strictly true -- you can write (1,) == 0 and it'll just return False.
However, there's discussion in python/mypy#1271, so I'm not sure what to do.
There was a problem hiding this comment.
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
vlasovskikh
commented
Jan 30, 2017
The attributes of I've added Since Lets either keep or remove both |
vlasovskikh
commented
Jan 30, 2017
I would try to keep typeshed universally applicable to all the type checkers. At least for now known incompatibility issues seem not that severe to me and I'm looking forward to make our code analysis in respect to understanding typeshed more compatible with PEP 484 and other type checkers. I hope the same applies to other contributors. |
JukkaL
commented
Jan 30, 2017
The intention of typeshed is to be useful for all Python type checkers. It's currently somewhat biased towards mypy and pytype, since they have used typeshed for the longest time, but we are happy to discuss the removal of mypyisms etc. These may take a while to be implemented, since they may require changes to mypy first. If we ask you to create a separate issue for something, it doesn't mean that we don't want that change. It may mean that we have to modify mypy before we can merge a part of a PR, since we also want to keep typeshed compatible with tools that already use it. |
vlasovskikh
commented
Jan 30, 2017
@JukkaL Yes, sure. I was answering to Guido's comment above about the possibility of adding analyzer-specific checks similar to |
gvanrossum
commented
Jan 30, 2017
For cases where the fix for mypy is difficult or debatable, we could implement a workaround in typeshed using MYPY=FalseifMYPY:
<versionformypy>else:
<versionforothertype-checkers>Assuming that other type-checkers treat |
ambv
commented
Jan 30, 2017
@vlasovskikh If we start sprinkling typeshed with |
vlasovskikh
commented
Jan 30, 2017
Lets at least try to continue without specific checks for type checkers. As we at PyCharm are gradually switching to typeshed we keep finding new PEP 484 incompatibilities in our checker. And we would prefer to fix them rather then add PyCharm-specific checks in stubs. |
gvanrossum
commented
Jan 30, 2017
via email
Of course, it's better if we don't have to use checker-specific code in the
stubs! Are you okay with the remaining open PRs that are either still under
discussion or failing? |
ambv
commented
Jan 30, 2017
Agreed, the less checker-specific code, the better. Andrey, maybe there's an easy way for you to provide us with some small checker that we could integrate as part of runtests.sh and Travis CI? That would help ensuring we don't introduce any problems in stubs for PyCharm in the future. |
vlasovskikh
commented
Jan 31, 2017
@gvanrossum Yes, I'm OK with that. We'll keep our own set of patches for the open PRs for a while. |
@ambv Good idea! We're setting up internal tests for typeshed stubs for PyCharm. I hope we will make them runnable as a part of runtests.sh eventually. |
gvanrossum
left a comment
There was a problem hiding this comment.
Again, a suggestion to move forward with the non-controversial changes separately.
| def __new__(cls) -> Any: ... | ||
| def __setattr__(self, name: str, value: Any) -> None: ... | ||
| def __eq__(self, o: object) -> bool: ... | ||
| def __ne__(self, o: object) -> bool: ... |
There was a problem hiding this comment.
Also, while the methods may not exist, the operations from which they are typically used (== and !=) do work on objects.
vlasovskikh
commented
Feb 7, 2017
@gvanrossum Agree, I'll re-send non-controversial bits of this request as another PR. |
No description provided.