Skip to content

@overload type checking for overload signatures #11283

@adusamr

Description

@adusamr

I read through #2806
Is there possibility of adding an opt in feature of type checking against overload signatures?
For default values, for example

@overload
def f() -> str: ...

@overload
def f(a: int) -> int: ...

@overload
def f(a: str) -> str: ...

def f(a: int | str | None = None) -> int | str:
    if a is None:
        return "None"
    return a

this def f() -> str: would be type checked the same as

def f() -> str:
    a = None
    if a is None:
        return "None"
    return a

I know there are cases where this behavior doesn't work, but if this feature exists, I would just happily enable it and prohibit implementation that doesn't align with it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions