Skip to content

Wrong overload resolution with Any union item in argument #5249

@JukkaL

Description

@JukkaL

This fragment derived from production code causes a false positive:

def f(): pass  # No annotation
t = False
t &= f() and True  # Incompatible types in assignment 
                   # (expression has type "int", variable has type "bool")

Here's a self-contained repro:

from typing import overload, Union, Any

class C:
    def f(self, other: C) -> C: ...

class D(C):
    @overload  # type: ignore
    def f(self, other: D) -> D: ...
    @overload
    def f(self, other: C) -> C: ...
    def f(self, other): ...

x: D
y: Union[D, Any]
reveal_type(x.f(y))  # C

I'd expect the inferred type for x.f(y) to be Union[D, Any] (or maybe D, though it's slightly less correct arguably).

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions