Closed
Description
When executing (plugin) function signature hooks, actual argument types are not available yet (and, in fact, there's no caller context).
In #14526, the signature of attr.evolve(inst, ...)
depended on the inst
argument, and we had no choice but to do
inst_arg = ctx.args[0][0]
assert isinstance(ctx.api, TypeChecker)
inst_type = ctx.api.expr_checker.accept(inst_arg)
Actual argument types are passed to the function hook, but then it's too late since arguments were already checked, and the hook can only affect the callee's return type.
I'm not sure what's the best approach:
- Add equivalent of
CheckerPluginInterface.accept
for ad-hoc type resolution (i.e. current solution but w/o private API). The assumption is that this will not normally be used by hook authors except in specific cases for specific args (since doing it generally creates a chicken-and-egg problem, asinfer_arg_types_in_context
gets the callee after the hook's mutation). - Pass actual arg types to function sig hook. Not sure it'll be doable, since as I mentioned
infer_arg_types_in_context
depends oncallee
(after hook's mutation). - Change function hook to allow returning not only a ret_type but also arg_types/kinds/names. This means that in those cases checks will be done twice: it first has to pass old formal sig, then (if plugin returns one) it has to pass the new formal sig.
Please advise :)
P.S. Same applies to method signature hook.