Skip to content

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

Open
@JukkaL

Description

@JukkaL

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions