diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2016-03-11 17:56:56 +0000 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2016-03-11 18:05:17 +0000 |
commit | ef60391de7efaff693f38cb00d4aeef5f1e4f1a9 (patch) | |
tree | 4c22abb27bd1ee0fedd8cf807d973f8b1391a628 | |
parent | d17dae59d3a008cca1093d3d3ca6df8f7091c250 (diff) | |
download | pylint-git-ef60391de7efaff693f38cb00d4aeef5f1e4f1a9.tar.gz |
Ignore __all__ elements that don't have a parent
There used to be a bug which involved astroid and extension modules,
where the elements of the __all__ declaration didn't have a parent set.
This problem was fixed though in astroid 2.0 and we can infer properly
these declarations with the parent being set. Unfortunately, we can't
rely on astroid 2.0 right now, so the solution for not having crashes
is to skip these elements in the undefined-all-variable pattern.
Close #846
-rw-r--r-- | pylint/checkers/variables.py | 2 | ||||
-rw-r--r-- | pylint/test/unittest_checker_variables.py | 8 |
2 files changed, 10 insertions, 0 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index f8f9c1b7c..209f7f717 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -372,6 +372,8 @@ builtins. Remember that you should avoid to define new builtins when possible.' continue if elt_name is astroid.YES: continue + if not elt_name.parent: + continue if (not isinstance(elt_name, astroid.Const) or not isinstance(elt_name.value, six.string_types)): diff --git a/pylint/test/unittest_checker_variables.py b/pylint/test/unittest_checker_variables.py index 0a235d4b2..e42dffcfd 100644 --- a/pylint/test/unittest_checker_variables.py +++ b/pylint/test/unittest_checker_variables.py @@ -38,6 +38,14 @@ class VariablesCheckerTC(CheckerTestCase): with self.assertNoMessages(): self.checker.visit_importfrom(node) + def test_all_elements_without_parent(self): + node = test_utils.extract_node('__all__ = []') + node.value.elts.append(astroid.Const('test')) + root = node.root() + with self.assertNoMessages(): + self.checker.visit_module(root) + self.checker.leave_module(root) + @set_config(callbacks=('callback_', '_callback')) def test_custom_callback_string(self): """ Test the --calbacks option works. """ |