Skip to content

fix ParamSpecs should allow for overload resolution #2642#2665

Open
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:2642
Open

fix ParamSpecs should allow for overload resolution #2642#2665
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:2642

Conversation

@asukaminato0721
Copy link
Contributor

Summary

Fixes #2642

Added ParamSpec-aware overload resolution when a Callable[P, ...] parameter is matched against an overloaded function with additional *args/**kwargs, so overload selection uses the call-site arguments before binding P. This fixes the premature overload selection in atexit.register.

Test Plan

Added a regression test that passes a matching overload through atexit.register with ParamSpec args.

@meta-cla meta-cla bot added the cla signed label Mar 5, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review March 5, 2026 09:11
Copilot AI review requested due to automatic review settings March 5, 2026 09:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes ParamSpec-aware overload resolution when a Callable[P, ...] parameter is passed an overloaded function and additional *args/**kwargs are supplied at the call site (e.g. atexit.register(f, ...)), so overload selection uses the forwarded arguments before binding P.

Changes:

  • Add a regression test covering atexit.register with an overloaded callback and ParamSpec-forwarded arguments.
  • Add a special-case in callable_infer_params to resolve an overloaded callable argument against the forwarded args, then bind P from the chosen overload’s parameters.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pyrefly/lib/test/paramspec.rs Adds regression test for ParamSpec + overload selection through atexit.register.
pyrefly/lib/alt/callable.rs Implements ParamSpec-aware overload selection/binding when the callable argument is overloaded.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +614 to +625
let (ret, chosen_sig) = self.call_overloads(
overloads,
&overload_for_call.metadata,
None,
&args[1..],
keywords,
arguments_range,
call_errors,
context,
None,
None,
);
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call_overloads always records an overload trace at arguments_range and can also emit NoMatchingOverload diagnostics. In this context we’re only using overload evaluation to bind the ParamSpec for the outer call, so recording traces / emitting errors for the inner overloaded function can produce incorrect IDE signature help and confusing error messages (it looks like the user “called” the overload). Consider using a temporary error collector (and ideally a path that doesn’t record overload traces), and only applying the result when a match is found.

Copilot uses AI. Check for mistakes.
Comment on lines +655 to +656
}
return;
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block returns unconditionally after calling call_overloads, even when ret.is_error() (no overload matched). That prevents the normal argument/ParamSpec binding logic from running and can leave only a NoMatchingOverload error for the passed-in function (or no error about the outer call argument) rather than a correctly-contextualized CallArgument/BadArgumentType diagnostic. Only early-return when overload resolution succeeds; otherwise fall through to the existing parameter matching logic.

Suggested change
}
return;
return;
}

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Mar 5, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@meta-codesync
Copy link

meta-codesync bot commented Mar 5, 2026

@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D95416116.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ParamSpecs should allow for overload resolution

2 participants