Repository navigation
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
👋 Thank you for your draft pull request! Do you know that you can use |
|
Definitely merits a changelog, given the added dependency, however proximate to core python. |
| return func.__func__ if isinstance(func, _method_types) else func | ||
|
|
||
|
|
||
| def _deprecation_message(alternative, pending): |
There was a problem hiding this comment.
In a followup PR this can be made a public function so people can have an Astropy-style deprecation message but use core python for their deprecations.
481d58a to
b0eafcf
Compare
|
Should probably update our decorator to also attach |
Isn't that what we did? We should indeed mimic what |
|
For classmethod and such we set |
|
Headsup: the |
|
It's also worth noting that it's actually not available in Python 3.12, and currently aimed at 3.13 |
|
Must say it makes more sense in the Still all in favour of mimicking the decorator's behaviour so that IDEs recognize our |
Agreed. This gives us many years to deprecate any duplicated functionality.
That would be nice. Pyright is probably the most used and we could potentially open an issue/PR. My thought is that this is all done statically and |
|
Checking on a function names seems fine, TBH. What decorator called |
deprecated internals to typing.deprecateddeprecated internals to warnings.deprecated
|
Just waiting for us to drop 3.11 |
| This decorator is a wrapper around `~typing.deprecated`, which was introduced by | ||
| `PEP 702 <https://peps.python.org/pep-0702/>`_ in Python 3.12. In lower versions of | ||
| Python, the `~typing_extenstions.deprecated` backport is used instead. There are a number of differences | ||
| between this decorator and `~typing.deprecated`, which are described below. |
There was a problem hiding this comment.
| between this decorator and `~typing.deprecated`, which are described below. | |
| between this decorator and `~warnings.deprecated`, which are described below. |
|
This has multiple conflicts now and I don't think we can even do it yet. Should we just close this PR? |
|
I'm fine to rebase and fix conflicts when we do drop Python 3.11. |
|
We'll need to drop 3.12 as well if we can't agree to have |
|
Re: #15307 (comment) On the other hand, I don't like introducing a dependency and then remove it again. This is not urgent so I don't see why we cannot wait longer. |
actually that would be my argument against most API removals (yes, deprecated ones), and these are going much faster in astropy than in most libraries I know of. |
|
I thought |
💯 |
|
@nstarman Python 3.11 has been dropped, so is it time to revisit this? |
|
Yes! I can get to this soon. |
b0eafcf to
e6d8061
Compare
Signed-off-by: nstarman <[email protected]>
e6d8061 to
ad35931
Compare
| This decorator is a wrapper around `warnings.deprecated`, which was introduced by | ||
| `PEP 702 <https://peps.python.org/pep-0702/>`_ in Python 3.13. On Python 3.12 the | ||
| ``typing_extensions.deprecated`` backport is used instead. There are a number of | ||
| differences between this decorator and `warnings.deprecated`: |
There was a problem hiding this comment.
I feel like this is too disruptive. deprecated and its associated decorators in this module is also widely used downstream. Why do we need to change anything here? You are free to use warnings.deprecated internally here as much as you want without touching this module, yes?
There was a problem hiding this comment.
I agree that changing our existing decorator is unnecessarily disruptive as it's public API. Ideally we should just... deprecate it ?
There was a problem hiding this comment.
I don't even wanna think about it. How do you deprecate the deprecation? Haha. But seriously, yes, but not until we help downstream move away from it first. It is going to be a long game.
There was a problem hiding this comment.
How are we going to deprecate the astropy decorator without a process like this?
We have this decorator because Python didn't (at time of writing).
I think a new core-Python mechanism for communicating deprecations is the invitation we should accept to reduce our non-core-code burden.
With this in place we can go further and deprecate the integrated message mechanism, replacing it with a helper function, so deprecations work like
from astropy.utils.decorators import deprecation_message
@warnings.deprecated(deprecation_message(...))
def func(...
Looking at the differences, I think the primary way this breaks downstream is in test suites, where it should have minimal impact on users.
Also, given that warnings.deprecated is recognized by static type checkers and ours isn't, IMO no one should be using ours. E.g. VSCode shows me a visible warning every time I go to use a warnings.deprecated object, even before running the program.
I think users are best served by being notified about deprecations early, which is quite literally impossible with our decorator. Now that is possible and is in Python, IMO it's a question of how we do this, not if.
There was a problem hiding this comment.
so deprecations work like
ah, maybe I should have looked at the PR again before I commented. I was thinking we would use the stdlib decorator directly within astropy itself, but clearly that's not the approach you are going with.
There was a problem hiding this comment.
Yeah, and I'd refactor the internals of deprecated to use it to generate the message.
There was a problem hiding this comment.
Setback encountered: @astropy.utils.deprecated sets __deprecated__ and prepends a .. deprecated:: <since> block to the docstring. warnings.deprecated sets __deprecated__ ONLY, so the Sphinx directive is not set.
Now I recall this was one reason I started with this PR, to keep the Sphinx stuff.
I'll work around this and open a PR for discussion.
There was a problem hiding this comment.
Well, that went pretty disastrously.
There was a problem hiding this comment.
Re: deprecation_message -- Instead of refactoring deprecated, what about you copy out the messaging code into this new function? I suspect you won't need like 95% of the stuff in deprecated to build a message?
There was a problem hiding this comment.
#20407 is the current state of the draft.
deprecation uses the new deprecation_msg. It's a nice simplification inside deprecation_msg, and it adds some better error messages for malformed messages.
fixes #15301.
Reimplements
astropy.utils.decorators.deprecatedon top of PEP 702'swarnings.deprecated(Python 3.13+), falling back to thetyping_extensionsbackport on 3.12. Our decorator keeps its own signature, default warning type, docstring rewriting, andclassmethod/staticmethodsupport; only the machinery underneath changes.typing_extensionsis added as a conditional dependency,python_version < '3.13', in bothdependenciesandbuild-system.requires(the build importsastropy). It drops out entirely once we require 3.13.Behaviour changes
Deprecating a class now follows PEP 702 semantics, which differ from what we did before:
__init__/__new__warned for every subclass instantiation and never on subclass creation.__deprecated__is set on the wrapped function as well as the wrapper, as PEP 702 specifies.Both are covered by
docs/changes/utils/15307.api.rstand theNotessection of the decorator's docstring. The only in-tree fallout wasTestRunner, which subclasses the deprecatedTestRunnerBase: importingastropy.tests.runnernow warns, soastropy/__init__.pyimports it inside thecatch_warningsblock that was already there formake_test_runner_in.TODO
astropy.utils.decorators.deprecatedto mentionwarnings.deprecated: what ours does differently and when one should use that one instead.