Skip to content

BUG: Allow no . at end if indented #239

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
merged 9 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
9 changes: 7 additions & 2 deletions numpydoc/tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def plot(self, kind, color="blue", **kwargs):
Parameters
----------
kind : str
Kind of matplotlib plot.
Kind of matplotlib plot, e.g.::

'foo'

color : str, default 'blue'
Color name or rgb code.
**kwargs
Expand Down Expand Up @@ -89,7 +92,9 @@ def sample(self):
Returns
-------
float
Random number generated.
Random number generated, e.g.::

1.0

See Also
--------
Expand Down
24 changes: 16 additions & 8 deletions numpydoc/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,13 @@ def extended_summary(self):

@property
def doc_parameters(self):
return self._get_doc_parameters()

def _get_doc_parameters(self, joiner=""):
parameters = collections.OrderedDict()
for names, type_, desc in self.doc["Parameters"]:
for name in names.split(", "):
parameters[name] = (type_, "".join(desc))
parameters[name] = (type_, joiner.join(desc))
return parameters

@property
Expand Down Expand Up @@ -329,8 +332,8 @@ def directives_without_two_colons(self):
def parameter_type(self, param):
return self.doc_parameters[param][0]

def parameter_desc(self, param):
desc = self.doc_parameters[param][1]
def parameter_desc(self, param, joiner=""):
desc = self._get_doc_parameters(joiner)[param][1]
# Find and strip out any sphinx directives
for directive in DIRECTIVES:
full_directive = ".. {}".format(directive)
Expand Down Expand Up @@ -541,12 +544,16 @@ def validate(func_name):
wrong_type=wrong_type,
)
)
if not doc.parameter_desc(param):
this_desc = doc.parameter_desc(param, "\n").rstrip("\n")
if not this_desc:
errs.append(error("PR07", param_name=param))
else:
if doc.parameter_desc(param)[0].isalpha() and not doc.parameter_desc(param)[0].isupper():
if this_desc[0].isalpha() and not this_desc[0].isupper():
errs.append(error("PR08", param_name=param))
if doc.parameter_desc(param)[-1] != ".":
# Not ending in "." is only an error if the last bit is not
# indented (e.g., quote or code block)
if this_desc[-1] != "." and \
not this_desc.split("\n")[-1].startswith(" "):
errs.append(error("PR09", param_name=param))

if doc.is_function_or_method:
Expand All @@ -560,10 +567,11 @@ def validate(func_name):
if not desc:
errs.append(error("RT03"))
else:
desc = " ".join(desc)
desc = "\n".join(desc)
if desc[0].isalpha() and not desc[0].isupper():
errs.append(error("RT04"))
if not desc.endswith("."):
if not desc.endswith(".") and \
not desc.split("\n")[-1].startswith(" "):
errs.append(error("RT05"))

if not doc.yields and "yield" in doc.method_source:
Expand Down