diff options
author | cpopa <devnull@localhost> | 2014-07-24 13:13:45 +0200 |
---|---|---|
committer | cpopa <devnull@localhost> | 2014-07-24 13:13:45 +0200 |
commit | e7cc4e247202ea5d6f5b74aab9923c2014dbede9 (patch) | |
tree | a25004bb0b0ce6b9bf44c08ce3e941d1ed600026 | |
parent | 1d6e80b96d9711634f042e5b5e9890b0998b0334 (diff) | |
download | pylint-e7cc4e247202ea5d6f5b74aab9923c2014dbede9.tar.gz |
Don't emit 'pointless-string-statement' for attribute docstrings. Closes issue #193.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | checkers/base.py | 18 | ||||
-rw-r--r-- | test/input/func_base_stmt_without_effect.py | 32 |
3 files changed, 49 insertions, 4 deletions
@@ -52,6 +52,9 @@ ChangeLog for Pylint * Do not let ImportError propagate from the import checker, leading to crash in some namespace package related cases. Closes issue #203. + * Don't emit 'pointless-string-statement' for attribute docstrings. + Closes issue #193. + 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 8136d0f..63b153b 100644 --- a/checkers/base.py +++ b/checkers/base.py @@ -349,7 +349,7 @@ class BasicErrorChecker(_BasicChecker): @check_messages('abstract-class-instantiated') def visit_callfunc(self, node): """ Check instantiating abstract class with - abc.ABCMeta as metaclass. + abc.ABCMeta as metaclass. """ try: infered = node.func.infer().next() @@ -373,7 +373,7 @@ class BasicErrorChecker(_BasicChecker): has_abstract_methods(infered)): self.add_message('abstract-class-instantiated', node=node) - + def _check_else_on_loop(self, node): """Check that any loop with an else clause has a break statement.""" if node.orelse and not _loop_exits_early(node): @@ -551,6 +551,18 @@ functions, methods if isinstance(expr, astroid.Const) and isinstance(expr.value, basestring): # treat string statement in a separated message + # Handle PEP-257 attribute docstrings. + # An attribute docstring is defined as being a string right after + # an assignment at the module level, class level or __init__ level. + scope = expr.scope() + if isinstance(scope, (astroid.Class, astroid.Module, astroid.Function)): + if isinstance(scope, astroid.Function) and scope.name != '__init__': + pass + else: + sibling = expr.previous_sibling() + if (sibling.scope() is scope and + isinstance(sibling, astroid.Assign)): + return self.add_message('pointless-string-statement', node=node) return # ignore if this is : @@ -689,7 +701,7 @@ functions, methods """just print a warning on exec statements""" self.add_message('exec-used', node=node) - @check_messages('bad-builtin', 'star-args', 'eval-used', + @check_messages('bad-builtin', 'star-args', 'eval-used', 'exec-used', 'missing-reversed-argument', 'bad-reversed-sequence') def visit_callfunc(self, node): diff --git a/test/input/func_base_stmt_without_effect.py b/test/input/func_base_stmt_without_effect.py index 6454de9..4844971 100644 --- a/test/input/func_base_stmt_without_effect.py +++ b/test/input/func_base_stmt_without_effect.py @@ -11,7 +11,7 @@ 'Used when an expression that is not a function call is assigned\ to nothing. Probably something else was intended.'), """ - +# pylint: disable=too-few-public-methods __revision__ = '' __revision__ @@ -39,3 +39,33 @@ ANSWER == to_be() # W0106, typical typo to_be() or not to_be() # W0106, strange conditional function call (or nonsens) to_be().title # W0106, very strange, maybe typo +GOOD_ATTRIBUTE_DOCSTRING = 42 +"""Module level attribute docstring is fine. """ + +class ClassLevelAttributeTest(object): + """ test attribute docstrings. """ + + good_attribute_docstring = 24 + """ class level attribute docstring is fine either. """ + second_good_attribute_docstring = 42 + # Comments are good. + + # empty lines are good, too. + """ Still a valid class level attribute docstring. """ + + def __init__(self): + self.attr = 42 + """ Good attribute docstring """ + attr = 24 + """ Still a good __init__ level attribute docstring. """ + val = 0 + for val in range(42): + val += attr + """ Invalid attribute docstring """ + self.val = val + + def test(self): + """ invalid attribute docstrings here. """ + self.val = 42 + """ this is an invalid attribute docstring. """ +
\ No newline at end of file |