-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add a NoImplicit return type specifier. #16095
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
@jakethesnake420 here is a bit of a hack that achieves exactly what you want: from typing import Any, Never
NoImplicitAny = Any | Never # `Any | Any` would also work
def f() -> NoImplicitAny: # error: Missing return statement [return]
if bool():
return "amongus" But I would from somewhere import foo as real_foo
FooResult = list[int | bytes | float], list[str | int | bytes]
def foo() -> FooResult:
return real_foo()
def bar() -> FooResult:
if bool:
return foo() # can cast(FooResult, x) if needed
else:
var = foo() + foo()
# forgot to return. error: Missing return statement [return] |
As discussed in python#7511, mypy's `--warn-no-return` isn't really a question of type safety. It does however enforce a rule that is "dear to Guido's heart", and I think we should enforce it for functions that explicitly return Any as well. Fixes python#16095
We can maybe just make this the default behaviour, let's see how #16102 goes |
Closing this as won't fix, see #16102 (comment) Maybe basedmypy can pick up the patch though ;-) |
Feature
Example:
mypy won't flag this as an error
Proposed functionality example:
mypy flags it. error: Implicit return [None]
sometimes when using cython functions it is difficult to specify the return type and sometimes the exact type is not important. I just want to specify that the return is not implicit for only some functions in a large codebase.
Its possible to cast the return type and specify but it seems overly complex and messy when does this way:
And then imagine how cluttered it gets after calling foo hundreds of times across the codebase
The text was updated successfully, but these errors were encountered: