Skip to content

False positive when calling overloaded function in Python 2 mode only #11609

Description

@JukkaL

The second call at the bottom of this example generates an unexpected error, but only in Python 2 mode:

from typing import Any, Literal, overload

@overload
def f(
    x,  # type: Any
    y,  # type: Literal[True]
):
    # type: (...) -> None
    pass

@overload
def f(
    x,  # type: Any
    y,  # type: Literal[False]
):
    # type: (...) -> None
    pass

def f(x, y):
    pass

f(1, False)  # OK
f((1 if int() else 1), False)  # Error

Here's the output:

t.py:23: error: No overload variant of "f" matches argument types "int", "bool"
t.py:23: note: Possible overload variants:
t.py:23: note:     def f(x: Any, y: Literal[True]) -> None
t.py:23: note:     def f(x: Any, y: Literal[False]) -> None

This is a regression from mypy 0.910.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions