Skip to content

Commit 9e7bee0

Browse files
committed
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
1 parent 9f12836 commit 9e7bee0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pylint/checkers/variables.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ def _check_all(self, node, not_consumed):
384384
continue
385385
if elt_name is astroid.YES:
386386
continue
387+
if not elt_name.parent:
388+
continue
387389

388390
if (not isinstance(elt_name, astroid.Const)
389391
or not isinstance(elt_name.value, six.string_types)):

pylint/test/unittest_checker_variables.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ def test_no_name_in_module_skipped(self):
3838
with self.assertNoMessages():
3939
self.checker.visit_importfrom(node)
4040

41+
def test_all_elements_without_parent(self):
42+
node = test_utils.extract_node('__all__ = []')
43+
node.value.elts.append(astroid.Const('test'))
44+
root = node.root()
45+
with self.assertNoMessages():
46+
self.checker.visit_module(root)
47+
self.checker.leave_module(root)
48+
4149
@set_config(callbacks=('callback_', '_callback'))
4250
def test_custom_callback_string(self):
4351
""" Test the --calbacks option works. """

0 commit comments

Comments
 (0)