8000 BUG: Ignore versionadded directive when checking for periods at docstring end by bengineer19 · Pull Request #22423 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: Ignore versionadded directive when checking for periods at docstring end #22423

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

Merged
Prev Previous commit
Next Next commit
BUG: Refactor to ignore versionchanged and deprecated directives.
  • Loading branch information
bengineer19 committed Aug 19, 2018
commit 25382b9bbabf1e1590cb872bb9ceedd1468e2e1f
17 changes: 10 additions & 7 deletions scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@


PRIVATE_CLASSES = ['NDFrame', 'IndexOpsMixin']
DIRECTIVES = ['.. versionadded', '.. versionchanged', '.. deprecated']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik, all sphinx directives start with .. so I think it's better to have just the names here.



def _load_obj(obj_name):
Expand Down Expand Up @@ -466,13 +467,15 @@ def validate_one(func_name):
'should start with a '
'capital letter'.format(param))

if '.. versionadded::' in doc.parameter_desc(param):
index = doc.parameter_desc(param).index('.. versionadded::')
# Check for periods at the end of the description before the
# versionadded directive
period_check_index = index - 1
else:
period_check_index = -1
period_check_index = -1
for directive in DIRECTIVES:
if directive in doc.parameter_desc(param):
# Get index of character before start of directive
index = doc.parameter_desc(param).index(directive) - 1
# If this directive is closest to the description, use it.
if index < period_check_index or period_check_index is -1:
period_check_index = index

if doc.parameter_desc(param)[period_check_index] != '.':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about creating a new property in the class Docstring that returns the parameter_desc but without directives?

I think the code will be much more readable if we have this logic there, and in this part of the code where all validations happen we simply have something like if doc.parameter_desc_without_directives(param)[-1] != '.':

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree that would be more useful and readable; I'll make a property.

param_errs.append('Parameter "{}" description '
'should finish with "."'.format(param))
Expand Down
0