Skip to content

Overloaded function is not assignable to Callable #2273

@auscompgeek

Description

@auscompgeek

Describe the Bug

pyrefly 0.50.1 says that an overloaded function is incompatible with a Callable that takes a union of the overload argument types and returns (a union of) the overload return types, resulting in bad-assignment or bad-argument-type errors being reported depending on context.

Minimum reproducible example:

from typing import *

@overload
def foo(x: int) -> str: ...

@overload
def foo(x: str) -> str: ...

def foo(x: int | str) -> str:
    return str(x)

bar: Callable[[int | str], str] = foo
# `Overload[
#   (x: int) -> str
#   (x: str) -> str
# ]` is not assignable to `(int | str) -> str` [bad-assignment]

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0AqADroRAAVwA3GJSi5UmEZhhg6YXLgAU%2BRJ3QMAlHQC0APjpwGlXYVsjxUmXIVKVajdt2XKRsxas2dqJYbupaOnr8AD7%2BPibm3ogidCl0lDAMAK6U6LHaBvbo2KjWdADCqFBQqNiwANp1rNGxALoANK10ALzuuCIgbSBk6WBQpIQMtFAUAMR0AAqkI2MWGDgEdADGuOiQbNmoDBA7hCJzAMowMHQAFgwMxHCIAPTPwypjhLxszzDoz5hcJs4M9trsIPtKIdjv93JQ6KhJKhoDVYFsdnsDkcdnRcMRseg4Kd0GQGDcdsZpJQ4DDunQhCAAMyEACMACYGf0AL6DVCbI7SABi0BgFDQWDwRDIIC5QA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions