-
Notifications
You must be signed in to change notification settings - Fork 766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add #[pyo3(deprecated(...))]
to #[pyfunction]
(#4316)
#4364
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much! I think this looks really good already. Just left some early thoughts while skimming through the macro code.
49621ba
to
2a4fe7d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation wise this looks good to me. I think for testing we still need
#[pymethods]
tests, probably intest_methods.rs
- coverage in the hygiene tests
- I think this also deserves a
pytest
For the docs, we might want to say somewhere that this is also available to #[pymethods]
, but I haven't seen a good place for that yet myself.
Thanks for the detailed feedback! I'll work on these points!! :) Regarding documenting this attribute for I'll add hygiene test for coverage a bit later. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks good. A couple of thoughts:
- Reading this, it feels like this is really just a general mechanism for raising warnings, not necessarily deprecation warnings. Should we maybe just call it pyo3(warn)? 🤔
- Should the message be optional? It seems like https://docs.python.org/3/library/warnings.html#warnings.warn allows this.
Fwiw I'm not sure about either. I'd welcome your and anyone else's thoughts
The name
The signature of If we are making the attribute named I'll work on additional testing and the compile error, and wait for more opinions on what this attribute should be called :) |
I like the idea of |
Reading this, I also think the general mechanism Probably the Having been away from the discussion for a while, did we decide strongly that we don't want to support the Rust In the (I think rare) case where users want a Rust deprecation but not a Python one, we could always have Finally, a style question. I think that |
Personally I'd want this shorthand to just be the Rust |
That sounds good! I will refactor the current one to |
There was some discussion about that in #4316. I kind of agree with the points made there, that reusing the
I think the most straight forward solution without additional complexity or "magic" is to stick to our options system, possibly with an option, opt-in or opt-out, to also emit the
I think this ( |
That makes sense. I still think that most commonly users will want to deprecate both sides at the same time and so tying both together with Rust's Let's go with |
I agree with both. I proposed in the issue that we could use something like In this way, users don't need to duplicate their deprecation note twice if they want to deprecate both sides. They also have the control of which side of deprecation they'd like to apply on. This seems to be a win-win for both sides. |
1f605b9
to
8fbbc54
Compare
Hi all! The The The Please let me know if I missed anything. Thanks! Best regards, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This mostly looks good to me. Just some minor things here and there.
I saw that you opened this to support multiple warnings. I currently don't see a big problem with that. It does however interact with automatic Rust deprecation since we currently could have multiple #[pyo3(deprecated)]
, but only one #[deprecated]
attribute is allowed per item, so we should be aware of the consequences before committing to anything here. Let's see what the others think of this. This would currently be the only pyo3 option that would be allowed multiple times (I think), so we should document that behavior somewhere if we decide to keep it.
I think we should add one or two of these attributes to the tests/hygiene
tests, to make sure all the emitted code is fully qualified.
Also it should be possible to use a user defined warning category that extends from PyWarning
. Maybe we should add a test to make sure that works?
The deprecated attribute currently only deprecates Python side. If we want to allow deprecated to deprecate both sides and add an opt-out option, like the #[pyo3(deprecated = "...", python_only)], I can add it later this week.
I'm open to this, but I would suggest if we decide to go down that route we should do it as a followup.
I agree we should be cautious on the multiplicity of the same attribute. I'm also curious what others think of this. :) |
Clippy fails on x86_64 linux target surprisingly, because of
It seems that |
Only on beta though. I wonder if that's a newly introduced rustc bug? |
Looks like so? The check had been passing until this one. Could you maybe rerun the check to see if the error goes away? |
This is just dead code detection getting better 🎉. It also happens on main. The reason is our reexport of Lines 25 to 26 in b2b5203
has a more restrictive gate than its type definition Lines 183 to 184 in b2b5203
So that type is actually not nameable on PyPy 3.8+ but it was actually intended to be. You don't have to worry about it here, we can fix that separately. I'll file a PR shortly, #4375. |
Awesome!! Thanks! |
69e770d
to
db90552
Compare
@miikkas That's a great suggestion! If I understand the PEP 702 correctly, @Icxolu All requested changes have been made and thanks for the detailed feedback! I also rebased on main to resolve the clippy error. It looks like nightly compiler is also getting better and emits new errors. I can open a separate PR to fix it. :) I also see that coverage is not hitting the target. They are mainly caused by functions in the Would it be helpful if I squash the commits now, because this thread is getting long? |
@FlickerSoul Thanks, implementation and tests look good to me. I don't think we need to worry too much about CodeCov not hitting these specific paths.
Please feel free to do so 😄
I leave that up to you, we have squash merging enabled anyway, so from that perspective it does not really matter. It stretches the thread a bit, but depending on your workflow the commits could be useful if we device to take a step back, more on that below.
@miikkas Thanks for bringing this to our attention. I can definitely see us supporting that. However I agree with @FlickerSoul that we should postpone that to a followup. This means we should carefully evaluate what we can and want to guarantee in this first base implementation. From my reading PEP 702 talks specifically about deprecations, and not warnings in general. This could force us to diverge This together with a possibility of automatic Rust cc @davidhewitt A second opinion here would be appreciated 🙃 |
- <a id="deprecated"></a> `#[pyo3(deprecated = "...")]` | ||
|
||
Set this option to display deprecation warning when the function is called in Python. | ||
This is equivalent to [`#[pyo3(warn(message = "...", category = PyDeprecationWarning))]`](#warn) or [`warnings.warn(message, DeprecationWarning)`](https://docs.python.org/3.12/library/warnings.html#warnings.warn). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to guarantee that these are equivalent? Especially with Pep 702 support, which we might only be able to properly provide for #[pyo3(deprecated = "...")]
. Maybe we should formulate this a bit more loosely to give us some wiggle room in a future where these might need to diverge a bit? cc @davidhewitt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree this should be changed. I wrote this before reading the PEP 702. The semantics of deprecated
in the PEP doesn't seem to match what I'm promising here. Using the same name thus could cause future confusion.
I agree multiple I'll wait on @davidhewitt's opinion before going for the implementation. :))
This makes sense. I can't think of a good API for this off the top of my head. Maybe David can shed some light on this as well :)) Again, thanks for the feedback. Much appreciated! |
db90552
to
1408a37
Compare
1408a37
to
aa14600
Compare
aa14600
to
8bc593f
Compare
This PR implements
#[pyo3(deprecated(message = "...", category = ...))]
attribute for#[pyfunction]
and#[pymethods]
. The new attribute works like the followingNote that this function does not deprecate rust function. Programmers need to add
#[deprecated]
attribute explicitly.Ref: (#4316)