Closed intgr closed 3 weeks ago
I don't think there is a fix, as Any
is compatible with everything, so it will always match the first overload. Reordering is also not possible, at least not until we get a "Not" type (python/typing#801).
As a hack, we could add another overload case, with argument type that no real type ever satisfies but only Any
can satisfy. Could we use the Never
type?
For reference Pyright is handling this just fine: https://pyright-play.net/?pyrightVersion=1.1.374&pythonVersion=3.14&strict=true&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoCCKcAUKJFACYCGM1AxgDbUDOLApi5trvkiwH0adJqxYkJldsCjsAHtWyN2ARgAU1EGgBchYgEooAWgB8UAHJgU7bSSj3MM-kNoNmbDVv22HvqCHYAN3ZqRgF4BHZPNEMoCRIpGXlFBGUAJmjdMAAjACt2ehhDUwsrGzsHJCdBYTcxaO8Kv38gkLCIqKbmh000Lt9DEiA
@intgr We could try your suggestion in an experimental PR. (We should definitely add tests, though.) Otherwise I would close this issue as unfixable.
Opened PR:
MyPy PR is here: https://github.com/python/mypy/pull/17678
I found this surprising and arguably incorrect. According to mypy:
(Mypy playground)
This is because
Any
matches the 1st overload, even if 2nd overload withobject
argument is more appropriate forAny
:I couldn't think of an elegant fix for this.