Skip to content
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

Support PEP-702 style deprecations #401

Open
12rambau opened this issue Aug 29, 2023 · 4 comments
Open

Support PEP-702 style deprecations #401

12rambau opened this issue Aug 29, 2023 · 4 comments

Comments

@12rambau
Copy link

To document my deprecation cycles, I usually use the deprecated lib. It's as simple to use as this:

from deprecated.sphinx import deprecated

@deprecated(version='1.0', reason="This function will be removed soon")
def function_three():
    '''This is the function three'''

function_three()  # warns
help(function_three)

as the decorator is changing the result of the help method, it's automatically adding information if the documentation is build with api-doc. with autoapi, as you don't load the method but only parse them, I think this is just getting ignored.

Would you think of a way to implement a workaround either from here or directly from their repository ?

@AWhetter
Copy link
Collaborator

This is always going to be a limitation of static analysis. We can't cater for every possible thing that can happen at runtime.

I think it would be reasonable to say that we could document which decorators a function/method is decorated with, and then it's up to the user to understand what the decorators mean. It's likely that we'll need to let users configure an allowlist/blocklist of which decorators to document.
Would this cover your use case well enough?

@12rambau
Copy link
Author

What would be the type of output ?
Would it be possible to rewrite it using a custom extention and thus make it look as it shoud (.. deprecated:: something will go wrong)?

Although I agree you can't catch everything, according to github 66000+ projects use this lib, which is more than the pydata-sophinx-theme so I would say it's a pretty big deal in the documentation community.

@AWhetter
Copy link
Collaborator

AWhetter commented Mar 8, 2024

PEP-702 introduces support for an official @deprecated() decorator (https://peps.python.org/pep-0702/). So I'm going to repurpose this issue to support that instead, whether it's imported from warnings or typing_extensions.

@AWhetter AWhetter changed the title autoapi is not compatible with the deprecated lib Support PEP-702 style deprecations Mar 8, 2024
@12rambau
Copy link
Author

I discussed a bit with the deprecated team, the scope of the lib is still wider than the one from PEP-702, Could I create some sort of plugin to change how this decorator is interpreted ?

Because I guess, it's just about reading the decorator itself and change the template accordingly right ?

from conf.py the parameter would be:

extra_decorator = {
    "deprecated": ".. deprecated:: {reason}"
}

Each key being the name of the decorator and the value the string to use at the end of the description using the parameter names if any.

From the parser side I check the decorators and if any I add them to the template if they are listed only. For the specific use case of PEP-702 the decorator would be in the default decorator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants