diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2018-06-15 10:58:42 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-06-15 10:58:42 +0200 |
commit | 7203436c77efc2c1d363b49b5dd4542478a40d2c (patch) | |
tree | 7625d1f15d26c63538cc150d2c8dabb54bfbc56c /astroid/protocols.py | |
parent | 4ffa9eab67944c9caa9c6c9eac2327358fb3983f (diff) | |
download | astroid-git-7203436c77efc2c1d363b49b5dd4542478a40d2c.tar.gz |
Drop the requirement that lhs and rhs should have the same number of elements when inferring Starred
This improves the capabilities a bit, since we know infer those as empty lists
Diffstat (limited to 'astroid/protocols.py')
-rw-r--r-- | astroid/protocols.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/astroid/protocols.py b/astroid/protocols.py index 64904524..9ebeb92a 100644 --- a/astroid/protocols.py +++ b/astroid/protocols.py @@ -586,18 +586,15 @@ def starred_assigned_stmts(self, node=None, context=None, asspath=None): except exceptions.InferenceError: yield util.Uninferable return - if rhs is util.Uninferable or not hasattr(rhs, 'elts'): - # Not interested in inferred values without elts. + if rhs is util.Uninferable or not hasattr(rhs, 'itered'): yield util.Uninferable return - elts = collections.deque(rhs.elts[:]) - if len(lhs.elts) > len(rhs.elts): - raise exceptions.InferenceError('More targets, {targets!r}, than ' - 'values to unpack, {values!r}.', - node=self, targets=lhs, - values=rhs, unknown=node, - context=context) + try: + elts = collections.deque(rhs.itered()) + except TypeError: + yield util.Uninferable + return # Unpack iteratively the values from the rhs of the assignment, # until the find the starred node. What will remain will @@ -608,11 +605,15 @@ def starred_assigned_stmts(self, node=None, context=None, asspath=None): for index, left_node in enumerate(lhs.elts): if not isinstance(left_node, nodes.Starred): + if not elts: + break elts.popleft() continue lhs_elts = collections.deque(reversed(lhs.elts[index:])) for right_node in lhs_elts: if not isinstance(right_node, nodes.Starred): + if not elts: + break elts.pop() continue # We're done |