diff options
author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-02-21 22:20:13 +0200 |
---|---|---|
committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-02-21 22:20:13 +0200 |
commit | ada48fb1d7776994341e1fa7522e3f13e41a7f53 (patch) | |
tree | 489eb3ba16b5ba1161f0efe0026b6401b113b633 | |
parent | 062999db0385f9f3f31df47f1ddbf84271ad0ab8 (diff) | |
download | pylint-ada48fb1d7776994341e1fa7522e3f13e41a7f53.tar.gz |
Don't emit not-iterating warnings when the builtin is used in an unpacking.
-rw-r--r-- | pylint/checkers/python3.py | 6 | ||||
-rw-r--r-- | pylint/test/unittest_checker_python3.py | 18 |
2 files changed, 24 insertions, 0 deletions
diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py index e708c4a..a60d0de 100644 --- a/pylint/checkers/python3.py +++ b/pylint/checkers/python3.py @@ -78,6 +78,12 @@ def _in_iterating_context(node): elif isinstance(parent.func, astroid.Getattr): if parent.func.attrname == 'join': return True + # If the call is in an unpacking, there's no need to warn, + # since it can be considered iterating. + elif (isinstance(parent, astroid.Assign) and + isinstance(parent.targets[0], (astroid.List, astroid.Tuple))): + if len(parent.targets[0].elts) > 1: + return True return False diff --git a/pylint/test/unittest_checker_python3.py b/pylint/test/unittest_checker_python3.py index 2407fc5..825e827 100644 --- a/pylint/test/unittest_checker_python3.py +++ b/pylint/test/unittest_checker_python3.py @@ -139,6 +139,22 @@ class Python3CheckerTest(testutils.CheckerTestCase): with self.assertNoMessages(): self.walk(module) + def as_iterable_in_unpacking(self, fxn): + node = test_utils.extract_node(""" + a, b = __({}()) + """.format(fxn)) + with self.assertNoMessages(): + self.checker.visit_callfunc(node) + + def as_assignment(self, fxn): + checker = '{}-builtin-not-iterating'.format(fxn) + node = test_utils.extract_node(""" + a = __({}()) + """.format(fxn)) + message = testutils.Message(checker, node=node) + with self.assertAddsMessages(message): + self.checker.visit_callfunc(node) + def iterating_context_tests(self, fxn): """Helper for verifying a function isn't used as an iterator.""" self.as_iterable_in_for_loop_test(fxn) @@ -149,6 +165,8 @@ class Python3CheckerTest(testutils.CheckerTestCase): self.as_used_in_variant_in_listcomp_test(fxn) self.as_argument_to_random_fxn_test(fxn) self.as_argument_to_str_join_test(fxn) + self.as_iterable_in_unpacking(fxn) + self.as_assignment(fxn) for func in ('iter', 'list', 'tuple', 'sorted', 'set', 'sum', 'any', 'all', |