Skip to content

Fix/deprecated decorator alias 5693 - #5719

Open
YashVerma-code wants to merge 3 commits into
pyrefly-org:mainfrom
YashVerma-code:fix/deprecated-decorator-alias-5693
Open

YashVerma-code wants to merge 3 commits into
pyrefly-org:mainfrom
YashVerma-code:fix/deprecated-decorator-alias-5693

Conversation

@YashVerma-code

Copy link
Copy Markdown

Fixes #5693

Summary

Pyrefly previously identified @deprecated(...) using purely syntactic string matching on call.func via SpecialExport::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.definitions to identify aliased imports from warnings or typing_extensions.

  • Bindings Phase : Resolved class decorators using self.as_special_export.

  • Solving Phase : In solve_decorator, verified the inferred type of the decorator expression against warnings.deprecated and typing_extensions.deprecated.

  • I am a human, and I fully understand the code I am submitting.

Tests Added

Added test_deprecated_call_with_alias and test_deprecated_call_with_module_alias in pyrefly/lib/test/calls.rs.

@meta-cla

meta-cla Bot commented Nov 22, 2026

Copy link
Copy Markdown

Hi @YashVerma-code!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Nov 22, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the cla signed label Nov 22, 2026
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

✅ 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 stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@stroxler

stroxler commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

For the correctness issue, you can repro the bug with this example:

In library.py:

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 x

In client.py:

from library import choose  # incorrect warning: `choose` is deprecated
choose("ok")                        # Correctly silent
choose(1)

@github-actions github-actions Bot added size/m and removed size/m labels Nov 25, 2026
@meta-codesync

meta-codesync Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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.)

@YashVerma-code

YashVerma-code commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

Thanks for the review @stroxler! I've updated the PR.

  • Fixed @overload detection during the exports phase to handle @typing.overload and aliases, ensuring per-signature deprecation doesn't mark the whole function deprecated
  • Moved decorator deprecation parsing to the binding phase via BindingsBuilder::as_special_export, storing it on BindingDecorator and eliminating redundant inference in solve_decorator.

This branch has not been deployed

No deployments
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.

Deprecation warnings are not emitted when the deprecated decorator is imported with an alias

3 participants