Skip to content

Let function signature hook have context of caller #14845

Closed
@ikonst

Description

@ikonst

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:

  1. 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, as infer_arg_types_in_context gets the callee after the hook's mutation).
  2. Pass actual arg types to function sig hook. Not sure it'll be doable, since as I mentioned infer_arg_types_in_context depends on callee (after hook's mutation).
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featuretopic-pluginsThe plugin API and ideas for new plugins

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions