diff options
author | Michal Nowikowski <godfryd@gmail.com> | 2014-07-26 07:36:12 +0200 |
---|---|---|
committer | Michal Nowikowski <godfryd@gmail.com> | 2014-07-26 07:36:12 +0200 |
commit | 67a56a24f5553f3579a76cbee1c0f1df61e23437 (patch) | |
tree | c929398325398a0a9ff322ec81d4c97717f695a3 | |
parent | 997937528f8a1946f4a528ad040139f6ec384a79 (diff) | |
parent | 585ca0b785e85c3f25f38f0511fb21246b35ec2a (diff) | |
download | pylint-67a56a24f5553f3579a76cbee1c0f1df61e23437.tar.gz |
Merged logilab/pylint into default
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | checkers/base.py | 12 | ||||
-rw-r--r-- | checkers/format.py | 38 | ||||
-rw-r--r-- | checkers/imports.py | 5 | ||||
-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 | ||||
-rw-r--r-- | test/test_func.py | 4 |
8 files changed, 127 insertions, 107 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/checkers/format.py b/checkers/format.py index 7b5eb64..cb31256 100644 --- a/checkers/format.py +++ b/checkers/format.py @@ -104,30 +104,26 @@ MSGS = { 'bracket or block opener.'), {'old_names': [('C0323', 'no-space-after-operator'), ('C0324', 'no-space-after-comma'), - ('C0322', 'no-space-before-operator')]}) + ('C0322', 'no-space-before-operator')]}), + 'W0331': ('Use of the <> operator', + 'old-ne-operator', + 'Used when the deprecated "<>" operator is used instead ' + 'of "!=".', + {'maxversion': (3, 0)}), + 'W0332': ('Use of "l" as long integer identifier', + 'lowercase-l-suffix', + 'Used when a lower case "l" is used to mark a long integer. You ' + 'should use a upper case "L" since the letter "l" looks too much ' + 'like the digit "1"', + {'maxversion': (3, 0)}), + 'W0333': ('Use of the `` operator', + 'backtick', + 'Used when the deprecated "``" (backtick) operator is used ' + 'instead of the str() function.', + {'scope': WarningScope.NODE, 'maxversion': (3, 0)}), } -if sys.version_info < (3, 0): - - MSGS.update({ - 'W0331': ('Use of the <> operator', - 'old-ne-operator', - 'Used when the deprecated "<>" operator is used instead ' - 'of "!=".'), - 'W0332': ('Use of "l" as long integer identifier', - 'lowercase-l-suffix', - 'Used when a lower case "l" is used to mark a long integer. You ' - 'should use a upper case "L" since the letter "l" looks too much ' - 'like the digit "1"'), - 'W0333': ('Use of the `` operator', - 'backtick', - 'Used when the deprecated "``" (backtick) operator is used ' - 'instead of the str() function.', - {'scope': WarningScope.NODE}), - }) - - def _underline_token(token): length = token[3][1] - token[2][1] offset = token[2][1] diff --git a/checkers/imports.py b/checkers/imports.py index 3242b75..5964a26 100644 --- a/checkers/imports.py +++ b/checkers/imports.py @@ -139,8 +139,9 @@ MSGS = { 'Used a module marked as deprecated is imported.'), 'W0403': ('Relative import %r, should be %r', 'relative-import', - 'Used when an import relative to the package directory is \ - detected.'), + 'Used when an import relative to the package directory is ' + 'detected.', + {'maxversion': (3, 0)}), 'W0404': ('Reimport %r (imported line %s)', 'reimported', 'Used when a module is reimported multiple times.'), diff --git a/test/input/func_docstring.py b/test/functional/docstrings.py index e73d8a3..4cdc37e 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 diff --git a/test/test_func.py b/test/test_func.py index 51b6ba3..225efc8 100644 --- a/test/test_func.py +++ b/test/test_func.py @@ -45,7 +45,7 @@ class LintTestNonExistentModuleTC(LintTestUsingModule): class TestTests(testlib.TestCase): """check that all testable messages have been checked""" PORTED = set(['I0001', 'I0010', 'W0712', 'E1001', 'W1402', 'E1310', 'E0202', - 'W0711', 'W0108']) + 'W0711', 'W0108', 'C0112']) @testlib.tag('coverage') def test_exhaustivity(self): @@ -58,8 +58,6 @@ class TestTests(testlib.TestCase): except KeyError: continue not_tested -= self.PORTED - if PY3K: - not_tested.remove('W0403') # relative-import self.assertFalse(not_tested) |