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

deprecated_args support #51

Closed
wants to merge 9 commits into from
Closed

deprecated_args support #51

wants to merge 9 commits into from

Conversation

mjhajharia
Copy link

This pull request adds support for arguments to be deprecated. I made this specifically because we're planning to use Deprecated in PyMC and we needed support for deprecating parameter for which names have been changed or if they're redundant. I have a draft of some messy regex to add deprecated warning just below a parameter's directive as well, i'll make a PR for that soon. if this is out of scope for this project let me know then we'll rename the fork and use that.

@mjhajharia
Copy link
Author

here's an example

image

@mjhajharia
Copy link
Author

 def regex_for_deprecated_args(docstring, deprecated_args):
         """
         This function uses regex for positioning deprecation warnings for parameters with their documentation.

         "\\n{1}\\w+:{1}"  - looks for the next parameter(formatted as [line break followed by some string ending with a colon ]) 
         that is defined in the documentation, so we introduce the warning right before that

         "\\n{1}\\w+\\n{1}-+\\n{1}" - looks for the next documentation section like "Parameters", "Examples", "Returns"
         these are followed by a line of dashes (------).

         we look through all of these possible endings to find the "endpoint" of the param definition and insert the deprecation warning there

         """
         for deprecated_arg in deprecated_args:
             doc=docstring.split(f'\n{deprecated_arg}:')[1]
             nextitem = re.search("\\n{1}\\w+:{1}", doc)
             nextsection = re.search("\\n{1}\\w+\\n{1}-+\\n{1}",doc)
             last = len(doc)
             n = min(nextitem.start(), nextsection.start(), last)
             y = len(docstring.split(f'\n{deprecated_arg}:')[0]) + len(f'\n{deprecated_arg}:')
             docstring = docstring[:y+n] + str(sphinxtext) + docstring[y+n:]
         return docstring

here's the [work in progress] code for auto-adding deprecated directive for a kwarg just below its definition. feel free to incorporate this

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

Successfully merging this pull request may close these issues.

None yet

2 participants