fix: improve decorator error messages for injected parameter mismatches#3570
Open
Arths17 wants to merge 3 commits into
Open
fix: improve decorator error messages for injected parameter mismatches#3570Arths17 wants to merge 3 commits into
Arths17 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
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
InvalidDecoratorerror 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, | ||
| )) |
This comment has been minimized.
This comment has been minimized.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_idAfter 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