Skip to content

Return value expected on def f() -> Optional[Type]: with plain return #1003

@darjus

Description

@darjus

mypy is expecting me to explicitly return None instead of return, but I'd expect that to be inferred as there's little point in me telling it i return None

def f(i: int) -> Optional[int]:
    if i > 3:
        return  # fails but return None works
    return i * 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions