Skip to content

fix: improve decorator error messages for injected parameter mismatches#3570

Open
Arths17 wants to merge 3 commits into
facebook:mainfrom
Arths17:issue-3569
Open

fix: improve decorator error messages for injected parameter mismatches#3570
Arths17 wants to merge 3 commits into
facebook:mainfrom
Arths17:issue-3569

Conversation

@Arths17
Copy link
Copy Markdown
Contributor

@Arths17 Arths17 commented May 24, 2026

This improves decorator-related diagnostics when a Callable[Concatenate[..., ...]] decorator injects a parameter into the wrapped function.

Before, the checker surfaced a low-level callable mismatch such as:

Argument (self: Self@ExternalApiTemplateListApi) -> ... is not assignable to parameter view with type (@_, str, ParamSpec(@_)) -> @_ in function with_current_tenant_id

After this change, the same case reports a function-level diagnostic that points to the wrapped function:

Function \get` is missing required parameter of type `str` injected by decorator `with_current_tenant_id``

This keeps ParamSpec / Concatenate semantics unchanged and only improves the diagnostic layer for decorator application.

Fixes #3569

Copilot AI review requested due to automatic review settings May 24, 2026 19:36
@meta-cla meta-cla Bot added the cla signed label May 24, 2026
Copy link
Copy Markdown

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 improves diagnostic quality when applying Callable[Concatenate[..., ...]]-style decorators that effectively inject an extra positional parameter into the wrapped function, replacing a low-level callable mismatch with a function-focused error.

Changes:

  • Enhance decorator-application diagnostics to detect a common “missing injected parameter” mismatch and emit a clearer InvalidDecorator error at the wrapped function’s name.
  • Thread the decoratee identifier into decorator application so diagnostics can point at the wrapped function.
  • Add a regression test covering the missing injected-parameter scenario (issue #3569).

Reviewed changes

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

File Description
pyrefly/lib/alt/function.rs Adds a targeted heuristic to produce a clearer decorator error message for injected-parameter mismatches and plumbs the function name into decorator application.
pyrefly/lib/test/decorators.rs Adds a regression test asserting the improved decorator diagnostic for a missing injected parameter.

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

Comment on lines +1638 to +1644
let missing = prefix.get(actual_params.len())?;
Some(format!(
"Function `{}` is missing required parameter of type `{}` injected by decorator `{}`",
decoratee_name.as_str(),
self.for_display(missing.ty().clone()),
decorator_name,
))
@github-actions github-actions Bot added size/m and removed size/m labels May 24, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added size/m and removed size/m labels May 24, 2026
@github-actions
Copy link
Copy Markdown

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

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.

decorator error message is very confusing

2 participants