pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

[Feature] warn on @deprecated

Open yangdanny97 opened this issue 9 months ago • 4 comments

Describe the Bug

https://typing.python.org/en/latest/spec/directives.html#deprecated

warn on the following:

  1. import deprecated class/function
  2. call deprecated function

For now, this can be a regular type error since we don't support different error levels yet. It should have its own error code(s) and be disabled by default to avoid causing false positives. Once we support warnings, we'll turn it on.

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

yangdanny97 avatar May 27 '25 15:05 yangdanny97

Hey, I am happy to do 1 or 2, which one are you looking into doing?

Alex-Aron avatar May 29 '25 23:05 Alex-Aron

@Alex-Aron I haven't started working on either of them so you're free to take your pick. I've split this into sub-issues. Please let us know which one you'd like to look at and if you have any questions :)

yangdanny97 avatar May 30 '25 01:05 yangdanny97

I can work on #402 . What files would you recommend looking at first? I was looking into modifying lib/binding/function.rs and binding.rs first. Just want to make sure I am looking in the right direction. Thanks :)

Alex-Aron avatar May 30 '25 14:05 Alex-Aron

@Alex-Aron

Function decoration info & other metadata is stored in this FuncFlags struct: https://github.com/facebook/pyrefly/blob/main/pyrefly/lib/types/callable.rs#L172

It would be a good starting point to see how that's populated & add a new is_deprecated field, then check the field and raise an error whenever it's called.

There's a few places that implicitly call functions under the hood and there's some nuances for overloads and such, but I was thinking maybe we can just start with the simple case where it's straightforward call expression: https://github.com/facebook/pyrefly/blob/bcc4ac7e7be208dd5234ee59b06a024115431c8f/pyrefly/lib/alt/expr.rs#L1388

yangdanny97 avatar May 31 '25 02:05 yangdanny97

Hey! I got an error up if @deprecated is above a function. Let me know how the pull request looks + any other general criticisms so I can improve future open source contributions.

Alex-Aron avatar Jun 01 '25 20:06 Alex-Aron

All the warnings should now be implemented. We might want to consider whether to show the deprecation message in the warning as the next step, or maybe just call it done.

fangyi-zhou avatar Sep 04 '25 20:09 fangyi-zhou

Thanks for your work on this! I think if it's easy to show the message we could add it, but otherwise I'm happy to consider this done until someone specifically requests it

yangdanny97 avatar Sep 04 '25 21:09 yangdanny97

Are we good to close this issue?

fangyi-zhou avatar Nov 20 '25 21:11 fangyi-zhou