Skip to content

Spurious complaint about return value in deferred function #4488

@JukkaL

Description

@JukkaL

Mypy incorrectly complains about the return statement in this program (with --strict-optional):

def f() -> str:
    y  # Causes f to be deferred
    x = None
    if int():
        x = ''
    if x is None:
        x = ''
    return x  # Incompatible return value type (got "Optional[Any]", expected "str")

y = int()

The expected behavior is clean output.

Note that f is deferred. The problem goes away when f is not deferred.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions