Skip to content

Give an error if there is a variable annotation within a function but no signature #3948

Description

@JukkaL

Mypy should perhaps give an error about a variable annotation in an otherwise unanotated function. Example:

def f():
    a: int = 'x'   # Maybe this annotation should be an error?

The rationale is that mypy will ignore the type annotation since the function is still considered unannotated, but this is confusing because there is an annotation within the function so it can appear to be annotated.

If --check-untyped-defs is being used this error shouldn't be generated.

Originally reported in #3945.

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions