Skip to content

Return type inference #128

@sharkdp

Description

@sharkdp

It would be great if we could infer return types for functions where it is not annotated

def f(x: int, y: str):
    if x > 10:
        return x
    elif x > 5:
        return y

reveal_type(f(some_int, "a"))  # ideally: int | str | None

It seems like it would simply be a union of all reachable return expressions (and possible None, if the function can implicitly return it — we already have functionality to detect that).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions