Skip to content

Commit

Permalink
missing-*-docstring can look for __doc__ assignments.
Browse files Browse the repository at this point in the history
Close #3301
  • Loading branch information
PCManticore committed Dec 16, 2019
1 parent 88c8ee4 commit e63e664
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Release date: TBA

Close #560

* ``missing-*-docstring`` can look for ``__doc__`` assignments.

Close #3301

* ``safe_infer`` can infer a value as long as all the paths share the same type.

Close #2503
Expand Down
18 changes: 18 additions & 0 deletions pylint/checkers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,9 @@ def _check_docstring(
):
"""check the node has a non empty docstring"""
docstring = node.doc
if docstring is None:
docstring = _infer_dunder_doc_attribute(node)

if docstring is None:
if not report_missing:
return
Expand Down Expand Up @@ -2167,6 +2170,21 @@ def _is_one_arg_pos_call(call):
return isinstance(call, astroid.Call) and len(call.args) == 1 and not call.keywords


def _infer_dunder_doc_attribute(node):
# Try to see if we have a `__doc__` attribute.
try:
docstring = node["__doc__"]
except KeyError:
return None

docstring = utils.safe_infer(docstring)
if not docstring:
return None
if not isinstance(docstring, astroid.Const):
return None
return docstring.value


class ComparisonChecker(_BasicChecker):
"""Checks for comparisons
Expand Down
4 changes: 4 additions & 0 deletions tests/functional/m/missing_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ def test(self, value):
@test.deleter
def test(self):
pass


class DocumentedViaDunderDoc(object):
__doc__ = "This one"

0 comments on commit e63e664

Please sign in to comment.