Repository navigation
Fix/deprecated decorator alias 5693 - #5719
YashVerma-code wants to merge 3 commits into
Conversation
|
Hi @YashVerma-code! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
✅ This PR meets all requirements from our pull request checklist. Note: this comment updates automatically after changes to the PR. Updates may take up to half an hour. |
stroxler
left a comment
There was a problem hiding this comment.
Thanks for the PR! I think there are two issues we need to clean up before we merge
Correctness: make sure that deprecation is per overload signature
The changed function-export path, pyrefly/lib/export/definitions.rs:1056–1074
now recognizes the renamed deprecation decorator, but still relies on the old spelling-only is_overload_decorator. That helper misses both @typing.overload and renamed @ov. Consequently, the export table incorrectly marks the entire function deprecated.
This is a problem because the
typing spec says @deprecated
on an overload only applies to that one overload signature, not the entire function.
Architecture: make sure we don't re-infer more often than necessary
pyrefly/lib/alt/solve.rs:7728–7758
infers the entire decorator expression, then re-infers its factory callee just for deprecation checks. We can reuse existing helpers to avoid this.
BindingsBuilder::as_special_export
already supports binding identity, aliases, and module attributes; the PR already uses it for classes.
|
For the correctness issue, you can repro the bug with this example: In import typing
from warnings import deprecated as mark
@typing.overload
@mark("Only int is deprecated")
def choose(x: int) -> int: ...
@typing.overload
def choose(x: str) -> str: ...
def choose(x: int | str) -> int | str:
return xIn from library import choose # incorrect warning: `choose` is deprecated
choose("ok") # Correctly silent
choose(1) |
|
This pull request has been imported. If you are a Meta employee, you can view this in D134553135. (Because this pull request was imported automatically, there will not be any future comments.) |
|
Thanks for the review @stroxler! I've updated the PR.
|
Fixes #5693
Summary
Pyrefly previously identified
@deprecated(...)using purely syntactic string matching oncall.funcviaSpecialExport::from_syntax. This caused decorators to be missed when imported under an alias (e.g.from warnings import deprecated as _deprecated) or through an aliased module (e.g.import warnings as w; @w.deprecated(...)).Solution
Exports Phase: Resolved imported decorator identifiers against
self.inner.definitionsto identify aliased imports fromwarningsortyping_extensions.Bindings Phase : Resolved class decorators using
self.as_special_export.Solving Phase : In
solve_decorator, verified the inferred type of the decorator expression againstwarnings.deprecatedandtyping_extensions.deprecated.I am a human, and I fully understand the code I am submitting.
Tests Added
Added
test_deprecated_call_with_aliasandtest_deprecated_call_with_module_aliasinpyrefly/lib/test/calls.rs.