Skip to content

DOC: Docstring script to not require ending period for bullet points #25786

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

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9bb2fa4
Check if parameter description ends with bullet point before raising …
EdAbati Mar 19, 2019
5fdfcc4
fixed Docstring.parameter_desc_list for empty line and multiple direc…
EdAbati Mar 24, 2019
8b4a99e
fixed PEP8 issue
EdAbati Mar 24, 2019
2b73e89
added test for parameters with bullet points
EdAbati Mar 26, 2019
587cb12
created method that check if parameter ends correctly
EdAbati Mar 26, 2019
c920656
added extra bullet point markers
EdAbati Mar 28, 2019
060a499
added docstrings to new methods
EdAbati Mar 31, 2019
7c5375e
added closing quote test
EdAbati Apr 3, 2019
6b0267a
added test for parameter with bullet points and directories
EdAbati Apr 3, 2019
b387d0e
removed unnecessary else
EdAbati Apr 28, 2019
aa240de
renamed parameter to has_proper_punctuation
EdAbati Apr 28, 2019
146fae1
Added comment to clarify _parsed_data behaviour
EdAbati Jun 26, 2019
85ac4f7
Replaced for loop with regex match
EdAbati Jun 26, 2019
5f3d146
Fixed mistake in comment
EdAbati Jun 26, 2019
f0a2bac
Merge branch 'upstream/master' into doc_bullets_test and resolve conf…
EdAbati Aug 4, 2019
43ae6ea
use namedtuples to identify parameter in parameter_desc_list
EdAbati Aug 8, 2019
1fec41d
Format code using black
EdAbati Aug 11, 2019
a4a8752
Merge remote-tracking branch 'upstream/master' into doc_bullets_test
EdAbati Aug 13, 2019
9c56d30
Minor format change with black
EdAbati Aug 13, 2019
90fc737
Merge remote-tracking branch 'upstream/master' into doc_bullets_test
EdAbati Sep 14, 2019
334ade4
Merge remote-tracking branch 'upstream/master' into doc_bullets_test
EdAbati Sep 15, 2019
01192c3
Merge remote-tracking branch 'upstream/master' into doc_bullets_test
EdAbati Sep 22, 2019
331e518
Tidying up with regex
EdAbati Sep 22, 2019
fe5d723
Simplified has_proper_punctuation with regex
EdAbati Sep 22, 2019
f556faa
remove unnecessary check
EdAbati Sep 23, 2019
8e75e80
Merge remote-tracking branch 'upstream/master' into doc_bullets_test
EdAbati Oct 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion scripts/tests/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,62 @@ def say_hello():
else:
return None

def parameters_with_bullet_points(self, method='min'):
"""
Allow bullet points to end without a period.

Parameters
----------
method : {'min', 'max'}, default 'min'
Parameter introduction:

* 'min': the description for min
* 'max': the description for max
"""
pass

def parameters_with_bullet_points1(self, method='min'):
"""
Allow long description in bullet points to end without a period.

Parameters
----------
method : {'min', 'max'}, default 'min'
Parameter introduction:

* 'min': the description for min
* 'max': the description for max that can also be very long and
requires an extra row
"""
pass

def parameters_bullet_points_and_directives(self, axis='index',
method='min'):
"""
Test bullets points and directories.

Parameters
----------
axis : {'index', 'columns'}, default 'index'
Parameter introduction and one directive:

* 'index': the description for index
* 'columns': the description for columns

.. versionchanged:: 0.1.2

method : {'min', 'max'}, default 'min'
Parameter introduction and two directives:

* 'min': the description for min
* 'max': the description for max

.. versionadded:: 0.1.2
.. deprecated:: 0.00.0
A description
"""
pass


class BadGenericDocStrings(object):
"""Everything here has a bad docstring
Expand Down Expand Up @@ -806,7 +862,9 @@ def test_good_class(self, capsys):

@pytest.mark.parametrize("func", [
'plot', 'sample', 'random_letters', 'sample_values', 'head', 'head1',
'contains', 'mode', 'good_imports', 'no_returns', 'empty_returns'])
'contains', 'mode', 'good_imports', 'no_returns', 'empty_returns',
'parameters_with_bullet_points', 'parameters_with_bullet_points1',
'parameters_bullet_points_and_directives'])
def test_good_functions(self, capsys, func):
errors = validate_one(self._import_path(
klass='GoodDocStrings', func=func))['errors']
Expand Down
42 changes: 41 additions & 1 deletion scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,46 @@ def parameter_desc(self, param):
desc = desc[:desc.index(full_directive)]
return desc

def parameter_desc_list(self, param):
"""Return a parameter description as a list.

Each line of the parameter docstring is a string in the list.
"""
i = list(self.doc_parameters).index(param)
desc_list = [line
# The 'Parameters' value of NumpyDocString._parsed_data is
# a list of tuples. Each tuple represents a parameter
# docstring parameter and has the description of
# the parameter as last element.
for line in self.doc._parsed_data['Parameters'][i][-1]
if line]
# Find and strip out any sphinx directives
directives_pattern = re.compile('.. ({})'.format('|'.join(DIRECTIVES)))
for desc_item in desc_list:
if re.match(directives_pattern, desc_item):
# Only retain any description before the directive
desc_list = desc_list[:desc_list.index(desc_item)]
break
return desc_list

def has_proper_punctuation(self, param):
"""Return True if a parameter description is terminated correctly.

A parameter description should always be terminated with a period, a
part from when it ends with a bullet point.
"""
if self.parameter_desc(param)[-1] == '.':
return True
else:
# Return True if a parameter description ends
# with a bullet point
for desc_line in self.parameter_desc_list(param)[::-1]:
if desc_line[0] in ['*', '-', '+', '•', '‣', '⁃']:
return True
elif desc_line[0:2] != ' ':
return False
return False

@property
def see_also(self):
return collections.OrderedDict((name, ''.join(desc))
Expand Down Expand Up @@ -724,7 +764,7 @@ def get_validation_data(doc):
else:
if not doc.parameter_desc(param)[0].isupper():
errs.append(error('PR08', param_name=param))
if doc.parameter_desc(param)[-1] != '.':
if not doc.has_proper_punctuation(param):
errs.append(error('PR09', param_name=param))

if doc.is_function_or_method:
Expand Down