-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Make mypy --warn-no-return clean #2332
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
Conversation
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.
Regarding those visitors, maybe the visitor superclass can be changed to make those visitors return Optional[T]
, and the subclasses can choose to override those methods using either -> None
or -> (whatever)
based on their behavior?
@@ -1853,7 +1856,7 @@ def current_str(self) -> str: | |||
def peek(self) -> Token: | |||
return self.tok[self.ind + 1] | |||
|
|||
def parse_error(self) -> None: | |||
def parse_error(self) -> ThrowsException: |
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 is super confusing. The function raises, but is also declared to return an exception, and its callers raise whatever it returns, but those raise statements are never raised because the called function raises. Wouldn't it be simpler to make this function actually return the exception and have the call sites actually raise the exception it returns?
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.
Yeah, that's much better.
That fix won't work. It might work if we were running under strict Optional (though we might explicitly forbid stuff like that; I'm not sure), but it definitely won't otherwise (because None is Void). :/ |
b024ac3
to
cb608a3
Compare
Looking some more at the code, I think the right solution might be to make |
Yeah that seems fine for now; fixing that issue in the long run is one of the motivations of #1783. |
eb302cf
to
59971a6
Compare
I made up a way to handle calling a function that itself always raises.
The only errors that remain are in checker.py, and it's not entirely clear to me what to do about them. A bunch of functions are declared as returning
Type
when they just don't, but they can't simply be changed because they're overriding functions from a superclass. See e.g.mypy/mypy/checker.py
Line 271 in b024ac3