diff options
author | cpopa <devnull@localhost> | 2013-07-25 10:06:47 +0300 |
---|---|---|
committer | cpopa <devnull@localhost> | 2013-07-25 10:06:47 +0300 |
commit | 4574f4ade8560c687099443274b028d35365daff (patch) | |
tree | 3f031b4a2c31ae091ad1900a052a5a004a014732 | |
parent | 62fb6ad894b88a5365e4641459c872b95cd481be (diff) | |
download | pylint-unpacking2.tar.gz |
Add test cases for good cases, check the targets before the inference.unpacking2
-rw-r--r-- | checkers/variables.py | 7 | ||||
-rw-r--r-- | test/input/func_unbalanced_tuple_unpacking.py | 15 |
2 files changed, 19 insertions, 3 deletions
diff --git a/checkers/variables.py b/checkers/variables.py index 367685d..ea297e5 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -545,15 +545,16 @@ builtins. Remember that you should avoid to define new builtins when possible.' @check_messages('unbalanced-tuple-unpacking') def visit_assign(self, node): """ Check unbalanced tuple unpacking for assignments. """ + if not isinstance(node.targets[0], (astroid.Tuple, astroid.List)): + return + try: - infered = next(node.value.infer()) + infered = node.value.infer().next() except astroid.InferenceError: return if not isinstance(infered, (astroid.Tuple, astroid.List)): return - if not isinstance(node.targets[0], (astroid.Tuple, astroid.List)): - return targets = node.targets[0].itered() values = infered.itered() diff --git a/test/input/func_unbalanced_tuple_unpacking.py b/test/input/func_unbalanced_tuple_unpacking.py index 7519b83..1c251f0 100644 --- a/test/input/func_unbalanced_tuple_unpacking.py +++ b/test/input/func_unbalanced_tuple_unpacking.py @@ -22,4 +22,19 @@ def do_stuff3(): first, second = range(100) return first + second +def do_stuff4(): + """ This is right """ + first, second = 1, 2 + return first + second + +def do_stuff5(): + """ This is also right """ + first, second = (1, 2) + return first + second + +def do_stuff6(): + """ This is right """ + (first, second) = (1, 2) + return first + second + |