maxfischer2781 / asyncstdlib

the missing toolbox for an async world
https://asyncstdlib.readthedocs.io
MIT License
234 stars 21 forks source link

[Bug]: Incorrect overload handling for Any #139

Open maxfischer2781 opened 7 months ago

maxfischer2781 commented 7 months ago

What happened?

Since typing.Any matches literally anything, for @overload that start with special cases these are always picked in untyped code. Instead, @overload should prefer the most generic, conservative case.

This is related to and got my attention by the pandas concat type hints bug that causes Any -> ??? paths to select None -> Never overloads.

Minimal Reproducible Example

# Type test
# MyPy "correctly" reports the unused type ignore

async def test_filter_any(aitr: "AsyncIterator[int | None]") -> None:
    filter_any: Any = ...  # < we don't know the actual type and don't care
    async for item in a.filter(filter_any, aitr):
        print(2 + item)  # type: ignore

Request Assignment [Optional]

maxfischer2781 commented 4 months ago

There currently seems to be no way to fix this for both MyPy and PyRight. See the open StackOverflow question How to overload functions to handle Any-arguments? for the current status quo.