You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ ./venv/bin/mypy t.py t.py:10: error: Expression is of type "Any", not "int" [assert-type]t.py:11: error: Expression is of type "Any", not "str" [assert-type]Found 2 errors in 1 file (checked 1 source file)
# TODO: handle overloads, just fall back to whatever the non-plugin code does
returnctx.default_return_type
The constrained type var example you have is a duplicate of #17411. Note that unconstrained type vars or bounded type vars should work correctly. In general, mypy's handling of constrained type vars is a little weird.
I think I'm hitting this as well in mypy 1.18.2. I won't post the actual code, but the gist is that the overload should be chosen based on an enum choice:
Have an enum "CommandsEnum" that describes a set of functions a function commands_core can perform
Have @overloads of that function with the command set to something like Literal[CommandsEnum.Command3]
Create a partial with do_comm3 = partial(commands_core, command=CommandsEnum.Command3)
Activity
asottile-sentry commentedon Jul 25, 2024
an alternative spelling with
TypeVars seems to not work either:ref: work around partial missing overload support
ref: work around partial missing overload support (#74976)
hauntsaninja commentedon Jul 26, 2024
Yes, the behaviour with overloads is unchanged from mypy 1.10. Shouldn't be too bad to add support for it.
mypy/mypy/plugins/functools.py
Lines 131 to 132 in d1d3c78
The constrained type var example you have is a duplicate of #17411. Note that unconstrained type vars or bounded type vars should work correctly. In general, mypy's handling of constrained type vars is a little weird.
Improve support for functools.partial of overloaded callable protocol (…
Improve support for functools.partial of overloaded callable protocol (…
ref: work around partial missing overload support (getsentry#74976)
AaronDMarasco commentedon Dec 10, 2025
I think I'm hitting this as well in mypy 1.18.2. I won't post the actual code, but the gist is that the overload should be chosen based on an enum choice:
enum"CommandsEnum" that describes a set of functions a functioncommands_corecan perform@overloads of that function with thecommandset to something likeLiteral[CommandsEnum.Command3]do_comm3 = partial(commands_core, command=CommandsEnum.Command3)It seems to always pick the "first" overload.