summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Nowikowski <godfryd@gmail.com>2014-07-26 07:45:33 +0200
committerMichal Nowikowski <godfryd@gmail.com>2014-07-26 07:45:33 +0200
commite78a81deb11af85da6678ff7d7c236c2c67e7d1f (patch)
tree6b8b12e89447b90ff208e92d00ce9b5470b9a1cc
parente03a152f6995f9ddb96d12b82cffb1b1e28386d3 (diff)
parent67a56a24f5553f3579a76cbee1c0f1df61e23437 (diff)
downloadpylint-e78a81deb11af85da6678ff7d7c236c2c67e7d1f.tar.gz
merge
-rw-r--r--ChangeLog9
-rw-r--r--checkers/base.py12
-rw-r--r--checkers/format.py36
-rw-r--r--checkers/imports.py5
-rw-r--r--test/functional/docstrings.py (renamed from test/input/func_docstring.py)156
-rw-r--r--test/functional/docstrings.txt8
-rw-r--r--test/messages/func_docstring.txt8
-rw-r--r--test/test_func.py4
8 files changed, 132 insertions, 106 deletions
diff --git a/ChangeLog b/ChangeLog
index 7365516..26cb291 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -74,6 +74,15 @@ ChangeLog for Pylint
* Use the proper mode for pickle when opening and writing the stats file.
Closes issue #148.
+ * Don't emit hidden-method message when the attribute has been
+ monkey-patched, you're on your own when you do that.
+
+ * Only emit attribute-defined-outside-init for definition within the same
+ module as the offended class, avoiding to mangle the output in some cases.
+
+ * Don't emit 'unnecessary-lambda' if the body of the lambda call contains
+ call chaining. Closes issue #243.
+
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 1d93a2d..2c0e215 100644
--- a/checkers/format.py
+++ b/checkers/format.py
@@ -105,6 +105,22 @@ MSGS = {
{'old_names': [('C0323', 'no-space-after-operator'),
('C0324', 'no-space-after-comma'),
('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)}),
'C0327': ('Mixed line endings LF and CRLF',
'mixed-line-endings',
'Used when there are mixed (LF and CRLF) newline signs in a file.'),
@@ -114,26 +130,6 @@ MSGS = {
}
-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)