diff options
author | cpopa <devnull@localhost> | 2014-07-25 18:06:10 +0200 |
---|---|---|
committer | cpopa <devnull@localhost> | 2014-07-25 18:06:10 +0200 |
commit | 32daab9a97c18d2fd81db232ed7453a8db762afe (patch) | |
tree | f69b098ea643b054612af32ab698f1501d5a5a81 | |
parent | c8cb305ddcfae15719ac73ffe50979217a7bd004 (diff) | |
download | pylint-32daab9a97c18d2fd81db232ed7453a8db762afe.tar.gz |
Don't emit 'missing-docstring' when the actual docstring uses `.format`. Closes issue #281.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | checkers/base.py | 12 | ||||
-rw-r--r-- | test/functional/docstrings.py (renamed from test/input/func_docstring.py) | 156 | ||||
-rw-r--r-- | test/functional/docstrings.txt | 8 | ||||
-rw-r--r-- | test/messages/func_docstring.txt | 8 |
5 files changed, 106 insertions, 81 deletions
@@ -79,6 +79,9 @@ ChangeLog for Pylint * Don't emit 'unnecessary-lambda' if the body of the lambda call contains call chaining. Closes issue #243. + * Don't emit 'missing-docstring' when the actual docstring uses `.format`. + Closes issue #281. + 2014-04-30 -- 1.2.1 * Restore the ability to specify the init-hook option via the diff --git a/checkers/base.py b/checkers/base.py index fb63c51..c1600b5 100644 --- a/checkers/base.py +++ b/checkers/base.py @@ -53,6 +53,7 @@ REVERSED_METHODS = (('__getitem__', '__len__'), ('__reversed__', )) PY33 = sys.version_info >= (3, 3) +PY3K = sys.version_info >= (3, 0) BAD_FUNCTIONS = ['map', 'filter', 'apply'] if sys.version_info < (3, 0): BAD_FUNCTIONS.append('input') @@ -1092,6 +1093,17 @@ class DocStringChecker(_BasicChecker): if node_type != 'module' and max_lines > -1 and lines < max_lines: return self.stats['undocumented_'+node_type] += 1 + if (node.body and isinstance(node.body[0], astroid.Discard) and + isinstance(node.body[0].value, astroid.CallFunc)): + # Most likely a string with a format call. Let's see. + func = safe_infer(node.body[0].value.func) + if (isinstance(func, astroid.BoundMethod) + and isinstance(func.bound, astroid.Instance)): + # Strings in Python 3, others in Python 2. + if PY3K and func.bound.name == 'str': + return + elif func.bound.name in ('str', 'unicode', 'bytes'): + return self.add_message('missing-docstring', node=node, args=(node_type,)) elif not docstring.strip(): self.stats['undocumented_'+node_type] += 1 diff --git a/test/input/func_docstring.py b/test/functional/docstrings.py index e73d8a3..9ef09f5 100644 --- a/test/input/func_docstring.py +++ b/test/functional/docstrings.py @@ -1,73 +1,83 @@ -# pylint: disable=R0201 - -__revision__ = '' - -def function0(): - """""" - -def function1(value): - # missing docstring - print value - -def function2(value): - """docstring""" - print value - -def function3(value): - """docstring""" - print value - -class AAAA(object): - # missing docstring - -## class BBBB: -## # missing docstring -## pass - -## class CCCC: -## """yeah !""" -## def method1(self): -## pass - -## def method2(self): -## """ yeah !""" -## pass - - def method1(self): - pass - - def method2(self): - """ yeah !""" - pass - - def method3(self): - """""" - pass - - def __init__(self): - pass - -class DDDD(AAAA): - """yeah !""" - - def __init__(self): - AAAA.__init__(self) - - def method2(self): - """""" - pass - - def method3(self): - pass - - def method4(self): - pass - -# pylint: disable=missing-docstring -def function4(): - pass - -# pylint: disable=empty-docstring -def function5(): - """""" - pass +# pylint: disable=R0201
+# -1: [missing-docstring]
+__revision__ = ''
+
+# +1: [empty-docstring]
+def function0():
+ """"""
+
+# +1: [missing-docstring]
+def function1(value):
+ # missing docstring
+ print(value)
+
+def function2(value):
+ """docstring"""
+ print(value)
+
+def function3(value):
+ """docstring"""
+ print(value)
+
+# +1: [missing-docstring]
+class AAAA(object):
+ # missing docstring
+
+## class BBBB:
+## # missing docstring
+## pass
+
+## class CCCC:
+## """yeah !"""
+## def method1(self):
+## pass
+
+## def method2(self):
+## """ yeah !"""
+## pass
+
+ # +1: [missing-docstring]
+ def method1(self):
+ pass
+
+ def method2(self):
+ """ yeah !"""
+ pass
+
+ # +1: [empty-docstring]
+ def method3(self):
+ """"""
+ pass
+
+ def __init__(self):
+ pass
+
+class DDDD(AAAA):
+ """yeah !"""
+
+ def __init__(self):
+ AAAA.__init__(self)
+
+ # +1: [empty-docstring]
+ def method2(self):
+ """"""
+ pass
+
+ def method3(self):
+ pass
+
+ # +1: [missing-docstring]
+ def method4(self):
+ pass
+
+# pylint: disable=missing-docstring
+def function4():
+ pass
+
+# pylint: disable=empty-docstring
+def function5():
+ """"""
+ pass
+
+def function6():
+ """ I am a {} docstring.""".format("good")
diff --git a/test/functional/docstrings.txt b/test/functional/docstrings.txt new file mode 100644 index 0000000..1ea5c7d --- /dev/null +++ b/test/functional/docstrings.txt @@ -0,0 +1,8 @@ +missing-docstring:1::Missing module docstring
+empty-docstring:6:function0:Empty function docstring
+missing-docstring:10:function1:Missing function docstring
+missing-docstring:23:AAAA:Missing class docstring
+missing-docstring:40:AAAA.method1:Missing method docstring
+empty-docstring:48:AAAA.method3:Empty method docstring
+empty-docstring:62:DDDD.method2:Empty method docstring
+missing-docstring:70:DDDD.method4:Missing method docstring
diff --git a/test/messages/func_docstring.txt b/test/messages/func_docstring.txt deleted file mode 100644 index 932df5e..0000000 --- a/test/messages/func_docstring.txt +++ /dev/null @@ -1,8 +0,0 @@ -C: 1: Missing module docstring -C: 5:function0: Empty function docstring -C: 8:function1: Missing function docstring -C: 20:AAAA: Missing class docstring -C: 36:AAAA.method1: Missing method docstring -C: 43:AAAA.method3: Empty method docstring -C: 56:DDDD.method2: Empty method docstring -C: 63:DDDD.method4: Missing method docstring |