From 75cc3326a92a1da3eb193b89fc65f5242df30691 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Sat, 10 Oct 2015 11:13:16 +0300 Subject: Don't warn about Starred nodes used properly in unpacking contexts Closes issue #653 --- pylint/checkers/base.py | 6 ++++++ pylint/test/functional/star_needs_assignment_target_py35.py | 5 +++++ pylint/test/functional/star_needs_assignment_target_py35.txt | 1 + 3 files changed, 12 insertions(+) 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 -- cgit v1.2.1