-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
comparison-overlap
not triggered for pathlib.Path
#10661
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
Comments
This is because of https://github.com/python/typeshed/pull/7231/files#diff-b5aebc9806d203cfe171e2215b0b4f3106395fc59687382eb9276d7d8976bffd , transferring to typeshed |
The I think the false negative here is just due to the heuristics mypy uses in order to avoid false positives for its |
It's not just mypy, pyright appears to use the same heuristic for its It seems the main benefit of |
Oh for sure, and I think it's a reasonable heuristic to use! That's why I thought it would probably be a wontfix if we considered it a mypy issue.
Sure, I agree that this is an unfortunate side effect of adding I guess we can remove But maybe I've been looking at it the wrong way :-) |
I.e. my basis for adding most of the |
I think given we haven't been particularly intentional here, #10464 was definitely the right thing to do. I guess a philosophy here could be:
But curious what other folks think! I'm also not actually sure how type checkers handle types on |
I'm on board with that — it sounds like a reasonably pragmatic approach. Though I'm still not thrilled about making decisions about what goes in the stubs based on these heuristics the type checkers are using, since it feels like the precise heuristics they use could be subject to change in the future. So for cases where we remove or purposefully omit
Fully agreed that this is the least important consideration |
Currently mypy and pyright will both complain at you if you have an |
Huh, mypy actually has a pretty detailed error message for that one. Yeah, that was meant as a suggestion for how type checkers could change how they interpret |
A few general thoughts. (I don't care about keeping
Maybe we could find a way to help type checkers better with strict overlap checks. For example, we could have @overload
def __eq__(self, other: PurePath) -> bool: ...
@overload
def __eq__(self, other: object) -> NotImplemented: ... Of course this is probably a discussion for typing-sig or discourse. |
A couple more thoughts:
|
The motivation is that it can often lead to false positives if they're not included in stubs. Lots of Python classes compare equal to objects of different classes -- it would be really annoying if you couldn't compare a >>> {1, 2, 3} == frozenset((1, 2, 3))
True
>>> {1, 2, 3} == dict.fromkeys((1, 2, 3)).keys()
True
>>> from types import MappingProxyType
>>> {1:2, 3:4} == MappingProxyType({1:2, 3:4})
True See e.g. #9580, where Jukka added |
Thank you all for the discussion, I learnt a lot! But can someone tell me what's the benefit of the current stub for The only typing-relevant difference between the default
So if I don't miss anything, removing the stub for
While it is true that type checkers might implement better heuristics in the future, I don't see any use for the current stub, while #10662 could prevent some nasty bugs. |
There would be a small regression caused by removing |
Fixes #10661 Co-authored-by: Alex Waygood <[email protected]>
--strict-comparison
seems to assume thatpathlib.Path
objects can be equal to anything.To Reproduce (playground)
Expected Behavior
Both lines should trigger 'non-overlapping equality check'
Actual Behavior
Only
'x' == 1
triggers 'non-overlapping equality check'The text was updated successfully, but these errors were encountered: