diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-10 11:13:16 +0300 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-10 11:13:16 +0300 |
commit | 75cc3326a92a1da3eb193b89fc65f5242df30691 (patch) | |
tree | 76c995d02ab639b506a345b1662f646fdcef134c | |
parent | d4395609c9e9454a1b18236626d8fe824fcc76aa (diff) | |
download | pylint-75cc3326a92a1da3eb193b89fc65f5242df30691.tar.gz |
Don't warn about Starred nodes used properly in unpacking contexts
Closes issue #653
-rw-r--r-- | pylint/checkers/base.py | 6 | ||||
-rw-r--r-- | pylint/test/functional/star_needs_assignment_target_py35.py | 5 | ||||
-rw-r--r-- | pylint/test/functional/star_needs_assignment_target_py35.txt | 1 |
3 files changed, 12 insertions, 0 deletions
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index 3029543..927e77b 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -64,6 +64,7 @@ REVERSED_METHODS = (SEQUENCE_PROTOCOL_METHODS, PY33 = sys.version_info >= (3, 3) PY3K = sys.version_info >= (3, 0) +PY35 = sys.version_info >= (3, 5) BAD_FUNCTIONS = ['map', 'filter'] if sys.version_info < (3, 0): BAD_FUNCTIONS.append('input') @@ -357,6 +358,11 @@ class BasicErrorChecker(_BasicChecker): # f(*args) is converted to Call(args=[Starred]), so ignore # them for this check. return + if PY35 and isinstance(node.parent, + (astroid.List, astroid.Tuple, + astroid.Set, astroid.Dict)): + # PEP 448 unpacking. + return stmt = node.statement() if not isinstance(stmt, astroid.Assign): diff --git a/pylint/test/functional/star_needs_assignment_target_py35.py b/pylint/test/functional/star_needs_assignment_target_py35.py index d2801de..58e43db 100644 --- a/pylint/test/functional/star_needs_assignment_target_py35.py +++ b/pylint/test/functional/star_needs_assignment_target_py35.py @@ -2,9 +2,14 @@ Test PEP 0448 -- Additional Unpacking Generalizations https://www.python.org/dev/peps/pep-0448/ """ + +# pylint: disable=superfluous-parens + UNPACK_TUPLE = (*range(4), 4) UNPACK_LIST = [*range(4), 4] UNPACK_SET = {*range(4), 4} UNPACK_DICT = {'a': 1, **{'b': '2'}} UNPACK_DICT2 = {**UNPACK_DICT, "x": 1, "y": 2} UNPACK_DICT3 = {**{'a': 1}, 'a': 2, **{'a': 3}} + +UNPACK_IN_COMP = {elem for elem in (*range(10))} # [star-needs-assignment-target] diff --git a/pylint/test/functional/star_needs_assignment_target_py35.txt b/pylint/test/functional/star_needs_assignment_target_py35.txt index e69de29..0777052 100644 --- a/pylint/test/functional/star_needs_assignment_target_py35.txt +++ b/pylint/test/functional/star_needs_assignment_target_py35.txt @@ -0,0 +1 @@ +star-needs-assignment-target:15::Can use starred expression only in assignment target
\ No newline at end of file |