Skip to content
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

Optional error code to flag missing return type when an argument has an annotation #15127

Open
JukkaL opened this issue Apr 25, 2023 · 4 comments · May be fixed by #15160
Open

Optional error code to flag missing return type when an argument has an annotation #15127

JukkaL opened this issue Apr 25, 2023 · 4 comments · May be fixed by #15160

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Apr 25, 2023

It's pretty common to see functions like this:

def foo(x: str):
    ...
    return <something>

Note that the function foo has an implicit Any 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.

@hauntsaninja
Copy link
Collaborator

Look at the code paths for --disallow-incomplete-defs

@Aditya-Sakpal
Copy link

Is this issue already been resolved?

@AVUKU-PRAGATHESWARI
Copy link

Is this issue solved..?

joaopedro-s added a commit to joaopedro-s/mypy that referenced this issue Jul 1, 2023
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 <31524775+saintleonar@users.noreply.github.com>
@Cnoor0171
Copy link

@JukkaL Hi. Isn't this already the way mypy behaves when the flag --disallow-incomplete-defs is used? For example, if I run mypy --disallow-incomplete-defs example.py on this file

# example.py
def foo(x: str):
    return 123

I get

example.py:2: error: Function is missing a return type annotation  [no-untyped-def]
Found 1 error in 1 file (checked 1 source file)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants