Skip to content

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

Merged
merged 6 commits into from
Nov 1, 2016
Merged

Make mypy --warn-no-return clean #2332

merged 6 commits into from
Nov 1, 2016

Conversation

ddfisher
Copy link
Collaborator

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.

def visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> Type:

Copy link
Member

@gvanrossum gvanrossum left a 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:
Copy link
Member

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?

Copy link
Collaborator Author

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.

@ddfisher
Copy link
Collaborator Author

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). :/

@ddfisher ddfisher force-pushed the self-warn-no-return branch from b024ac3 to cb608a3 Compare October 31, 2016 22:24
@ddfisher
Copy link
Collaborator Author

Looking some more at the code, I think the right solution might be to make TypeChecker inherit from NodeVisitor[Type] and have some functions explicitly return None (which is the case in some of them already).

@ddfisher ddfisher changed the title [WIP] Make mypy --warn-no-return clean Make mypy --warn-no-return clean Oct 31, 2016
@rwbarton
Copy link
Contributor

Yeah that seems fine for now; fixing that issue in the long run is one of the motivations of #1783.

@ddfisher ddfisher force-pushed the self-warn-no-return branch from eb302cf to 59971a6 Compare November 1, 2016 00:30
@gvanrossum gvanrossum merged commit 6918ccf into master Nov 1, 2016
@gvanrossum gvanrossum deleted the self-warn-no-return branch November 1, 2016 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants