Skip to content

overloaded function with broken with map dependent on order of overload definitions #3170

@DerBiasto

Description

@DerBiasto

Describe the Bug

I have a function taking some value or None that returns a value of the same type.

When trying to map that function onto an iterable of values, pyrefly gives an error, but only if the None overload is defined first. Moving the overload for done after any other overload, resolves this error.

from typing import overload, reveal_type

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

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

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

def foo(x: int | float | None) -> int | float | None:
    return x

def bar(items: tuple[int, ...]):
    for x in map(foo, items):  # Argument `tuple[int, ...]` is not assignable to parameter `iterable` with type `Iterable[None]` in function `map.__new__` [bad-argument-type]
        reveal_type(x)

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN24AbjEpRcqTABo6lGMNRQA%2Bk2IwAOug0ABISLESNmGGDphcuABT5EdAHK50MAJR0AtAD47DmDcJ%2BN2rqi4piGxqbmVjZg%2BgwuHqaxvv6a6DrCwQZY4WaW1pzocW6erAzJhAHZJrlRBfwAPoniDV6O8SWFdI0xzV2tPhp0QzIwDACulOh0%2BJVGJtiolBYQDDA0cDbjxLAA2qXSfoQAuk6Ig8NmlNMFdDSoxBa50itrcKfnw8Oy8koqMFZODQgSQgMiyGKkQgMWhQCgAYjoAAVSOCoKQ6GgsHh8HQAMYOSBsCaoBgQBwVdAIgDKMBgdAAFgwGMQNgB6Vlg4xowi8NismDoVmYXC4uCs-HoQnE0kOVkRK6oQSoaCobCwPEEiBEygkslTXDEGXoOAUsgMekOVwZOB6ugAXjoahAAGZCABGABMTo0OxE1EocCOGjG6C4PD4MEwrkwEFkuNJwntdAA5Fr0LwYMmNOmGK5ZABHMaxyOuADWMFIrlQuNx8DgSeTAHdFugs%2BgQABfEHVhMwABi0BgFExOAIJHIHaAA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions