Skip to content

Detect incorrect overload defaults #651

Open
@MarcoGorelli

Description

@MarcoGorelli

Same request as in python/mypy#19411 (comment), but just the "detect incorrect default" part, as the "missing default" part might not be a good idea after all

(as discussed on discord)

Example:

from typing import Literal, overload, reveal_type

@overload
def foo(a: Literal[True] = ...) -> None: ...
@overload
def foo(a: Literal[False]) -> int: ...
def foo(a: bool = False) -> None | int:
    return 1 if not a else None

reveal_type(foo())

I'd like Pyrefly to flag that a: Literal[True] = ... is incorrect, as the default (False) has no overlap with Literal[True]

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions