diff options
author | cpopa <devnull@localhost> | 2014-04-22 20:49:52 +0300 |
---|---|---|
committer | cpopa <devnull@localhost> | 2014-04-22 20:49:52 +0300 |
commit | 41ce7ee12f464ba0c2a5967a43e1a1a93f1081c6 (patch) | |
tree | 21b74cef4fdfd38d0505d14893a4a50b577c6d40 | |
parent | 7d1269a88635cd5433be0c0cd425b98878fe323e (diff) | |
download | pylint-41ce7ee12f464ba0c2a5967a43e1a1a93f1081c6.tar.gz |
Extend the checking for unbalanced-tuple-unpacking and unpacking-non-sequence to instance attribute unpacking as well.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | checkers/variables.py | 4 | ||||
-rw-r--r-- | test/input/func_unbalanced_tuple_unpacking.py | 9 | ||||
-rw-r--r-- | test/input/func_unpacking_non_sequence.py | 20 | ||||
-rw-r--r-- | test/messages/func_unbalanced_tuple_unpacking.txt | 2 | ||||
-rw-r--r-- | test/messages/func_unpacking_non_sequence.txt | 5 |
6 files changed, 39 insertions, 6 deletions
@@ -1,6 +1,11 @@ ChangeLog for Pylint ==================== +-- + + * Extend the checking for unbalanced-tuple-unpacking and + unpacking-non-sequence to instance attribute unpacking as well. + 2014-04-18 -- 1.2.0 * Pass the current python paths to pylint process when invoked via epylint. Fixes BitBucket issue #133. diff --git a/checkers/variables.py b/checkers/variables.py index 4bc0162..2ce7fcf 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -605,10 +605,6 @@ builtins. Remember that you should avoid to define new builtins when possible.' return targets = node.targets[0].itered() - if any(not isinstance(target_node, astroid.AssName) - for target_node in targets): - return - try: for infered in node.value.infer(): self._check_unpacking(infered, node, targets) diff --git a/test/input/func_unbalanced_tuple_unpacking.py b/test/input/func_unbalanced_tuple_unpacking.py index c2e01e9..216d520 100644 --- a/test/input/func_unbalanced_tuple_unpacking.py +++ b/test/input/func_unbalanced_tuple_unpacking.py @@ -68,3 +68,12 @@ def do_stuff9(): """ This is not correct """ first, second = unpack() return first + second + +class UnbalancedUnpacking(object): + """ Test unbalanced tuple unpacking in instance attributes. """ + # pylint: disable=attribute-defined-outside-init, invalid-name, too-few-public-methods + def test(self): + """ unpacking in instance attributes """ + self.a, self.b = temp() + self.a, self.b = temp2() + self.a, self.b = unpack() diff --git a/test/input/func_unpacking_non_sequence.py b/test/input/func_unpacking_non_sequence.py index 469add7..6fee0bf 100644 --- a/test/input/func_unpacking_non_sequence.py +++ b/test/input/func_unpacking_non_sequence.py @@ -1,6 +1,6 @@ """Check unpacking non-sequences in assignments. """ -# pylint: disable=too-few-public-methods, invalid-name +# pylint: disable=too-few-public-methods, invalid-name, attribute-defined-outside-init, unused-variable from os import rename as nonseq_func from input.unpacking import nonseq @@ -66,3 +66,21 @@ a, b = nonseq a, b = nonseq() a, b = bad_unpacking() a, b = nonseq_func + +class ClassUnpacking(object): + """ Check unpacking as instance attributes. """ + + def test(self): + """ test unpacking in instance attributes. """ + + self.a, self.b = 1, 2 + self.a, self.b = {1: 2, 2: 3} + self.a, self.b = "xy" + self.a, c = "xy" + c, self.a = good_unpacking() + self.a, self.b = Iter() + + self.a, self.b = NonSeq() + self.a, self.b = ValueError + self.a, self.b = bad_unpacking() + self.a, c = nonseq_func diff --git a/test/messages/func_unbalanced_tuple_unpacking.txt b/test/messages/func_unbalanced_tuple_unpacking.txt index c9311cc..59031e4 100644 --- a/test/messages/func_unbalanced_tuple_unpacking.txt +++ b/test/messages/func_unbalanced_tuple_unpacking.txt @@ -3,4 +3,6 @@ W: 14:do_stuff1: Possible unbalanced tuple unpacking with sequence [1, 2, 3]: le W: 19:do_stuff2: Possible unbalanced tuple unpacking with sequence (1, 2, 3): left side has 2 label(s), right side has 3 value(s) W: 50:do_stuff7: Possible unbalanced tuple unpacking with sequence defined at line 46: left side has 2 label(s), right side has 3 value(s) W: 69:do_stuff9: Possible unbalanced tuple unpacking with sequence defined at line 7 of input.unpacking: left side has 2 label(s), right side has 3 value(s) +W: 77:UnbalancedUnpacking.test: Possible unbalanced tuple unpacking with sequence defined at line 46: left side has 2 label(s), right side has 3 value(s) +W: 79:UnbalancedUnpacking.test: Possible unbalanced tuple unpacking with sequence defined at line 7 of input.unpacking: left side has 2 label(s), right side has 3 value(s) diff --git a/test/messages/func_unpacking_non_sequence.txt b/test/messages/func_unpacking_non_sequence.txt index 4099e29..7386f10 100644 --- a/test/messages/func_unpacking_non_sequence.txt +++ b/test/messages/func_unpacking_non_sequence.txt @@ -6,4 +6,7 @@ W: 65: Attempting to unpack a non-sequence defined at line 9 of input.unpacking W: 66: Attempting to unpack a non-sequence defined at line 11 of input.unpacking W: 67: Attempting to unpack a non-sequence defined at line 58 W: 68: Attempting to unpack a non-sequence - +W: 83:ClassUnpacking.test: Attempting to unpack a non-sequence defined at line 52 +W: 84:ClassUnpacking.test: Attempting to unpack a non-sequence +W: 85:ClassUnpacking.test: Attempting to unpack a non-sequence defined at line 58 +W: 86:ClassUnpacking.test: Attempting to unpack a non-sequence |