-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Optional error code to flag missing return type when an argument has an annotation #15127
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
Look at the code paths for |
Is this issue already been resolved? |
Is this issue solved..? |
Adding optional error flag for missing return type, when a function has at least one typed argument. This will address issue python#15127 Co-Authored-By: Leonardo Abreu Santos <[email protected]>
@JukkaL Hi. Isn't this already the way mypy behaves when the flag # example.py
def foo(x: str):
return 123 I get
|
Is this issue solved? If not, can I work on it? |
disallow-incomplete-defsExample 1: No Annotation --> No error
Example 2: Atleast 1 arg has annotation, but is missing return type annotation --> mypy throw errors for return type but doesnt suggest the use of -> None if the function never returns a value which would be nice to have
disallow-untyped-defsExample 1: if we have no annotations, it suggests user the use of -> None
Example 2: if we have annotation for atleast 1 argument , it DOES NOT suggests user the use of -> None
So, this behavior needs can be made consistent by adding a note suggesting the use of -> None if the function never returns a value for cases when atleast one arg in the function is annotated. |
I am working on this as part of PyCon US 2025 Sprints |
It's pretty common to see functions like this:
Note that the function
foo
has an implicitAny
return type, which is likely not what the programmer intended.Add a new error code (disabled by default since this is a backward compatibility break) that generates an error about a missing return type if at least one argument has an explicit type annotation. The error could be something like 'Function "foo" has no return type annotation', and perhaps add a note suggesting the use of
-> None
if the function never returns a value.We might eventually enable the error code by default as part of a major mypy release, such as 2.0 or 3.0.
The text was updated successfully, but these errors were encountered: