-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Incorrect "implicitly abstract" function when function returns None and implementation is 'pass' #13770
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 was implemented in this patch #12118 It uses a weak heuristic to guess whether a method is abstract and gives no option (that I can find) to disable the guess. How about a a command line option to disable "type checks" that makes wild guesses about the author's intention? |
FWIW, pyright treats |
I think that treating @ilevkivskyi @thomkeh What do you think? |
Yes, I agree. The reason why I did it this way was simply that mypy already had the In addition to Line 6313 in a68f0a5
Oh, by the way, I initially treated functions returning |
I don't like an idea of having a flag for this. I also don't like deciding implicit abstractness depending on the return type (optional vs non-optional). We just need to agree on such a set of rules about what is implicitly abstract that would satisfy everyone. Anecdotally, there are some post-Python 2 code bases that still have |
I'm pretty happy with the current rules. The error message is clear
It much more clearly communicates something is different than the difference between "..." and "pass". So I'd vote to close this issue. |
To many programmers, particularly from other languages like C++, this goes against common programming idioms. Returning a value from a function typed as void/None is an error. The ellipses are fine. Why does there need to be more heuristic than that? Having spurious return statements in functions that are not supposed to return a value is going to lead to readability and other bugs. I think there's an argument to be made that it is a typing error when functions declared as None return any value, even None. |
This also works:
I'd be in favour of changing the error message to say "explicitly |
A I still think FWIW this overall feature caught a few edge cases (actual missing abstract methods) in our code that I fixed too, although they weren't actually reachable. Thanks! |
Some methods became imlicitly abstract when the body is empty (using just `pass`). The work around seems to be to replace `pass` with `return`. More information can be seen on the relevant issue: python/mypy#13770
Bug Report
To Reproduce
Expected Behavior
This is valid code. The
optional_method
is optional and is implemented with a valid do-nothing body. It doesn't make sense toreturn None
from this function.Actual Behavior
Your Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: