-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Do not emit unreachable warnings for lines that return NotImplemented
.
#20083
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
Do not emit unreachable warnings for lines that return NotImplemented
.
#20083
Conversation
Diff from mypy_primer, showing the effect of this PR on open source code: yarl (https://github.com/aio-libs/yarl)
+ yarl/_url.py:550: error: Unused "type: ignore" comment [unused-ignore]
|
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.
I think this makes sense to me, even if it complicates the general idea of what exactly is exempt from unreachability warnings. (I guess now it's "anyway to bail out is OK"?)
I can also see this being unnecessary :^). Given nobody has complained, I'm not sure we really need to add this as a feature (since that's ultimately what this is).
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.
I think this is a good idea. See #363 (yes, three-digit issue number!) - this removes an unreachable
warning from the "should be fine" snippet there. I guess it has never been explicitly reported only because --warn-unreachable
is hidden too well, many users aren't even aware that it exists.
Wow, I overlooked this dinosaur. That's a nice tool you have! Interpreting class A1:
x = 1
def __add__(self, o: A1) -> float:
if isinstance(o, A1):
return self.x + o.x
return NotImplemented
class A2:
x = 2
def __add__(self, o: A2) -> float:
return self.x + o.x
class B:
y = 3
def __radd__(self, o: A1 | A2) -> float:
return self.y + o.x
A1() + B() # works
A2() + B() # fails (undetected by Mypy) I will try to find a fix for this as soon as I have some spare time.
Yes, I agree. As soon as
It would say it is more of a fix than a feature, because |
Thanks for the reviews! |
I think no one has complained so far. I just encountered this (in my understanding) lack in
TypeChecker.is_noop_for_reachability
working on #20068.