Open andreinaku opened 6 months ago
Targets that are iterables can be lists
or tuples
.
from ast.Assignment docs:
Multiple nodes in targets represents assigning the same value to each. Unpacking is represented by putting a Tuple or List within targets.
>>> code1 = 'a,b = 1,2.5'
>>> print(ast.dump(ast.parse(code1), indent=4))
Module(
body=[
Assign(
targets=[
Tuple(
elts=[
Name(id='a', ctx=Store()),
Name(id='b', ctx=Store())],
ctx=Store())],
value=Tuple(
elts=[
Constant(value=1),
Constant(value=2.5)],
ctx=Load()))],
type_ignores=[])
>>> code2 = 'a,b = [1,2.5]'
>>> print(ast.dump(ast.parse(code2), indent=4))
Module(
body=[
Assign(
targets=[
Tuple(
elts=[
Name(id='a', ctx=Store()),
Name(id='b', ctx=Store())],
ctx=Store())],
value=List(
elts=[
Constant(value=1),
Constant(value=2.5)],
ctx=Load()))],
type_ignores=[])
>>> code3 = '[a,b] = [1,2.5]'
>>> print(ast.dump(ast.parse(code3), indent=4))
Module(
body=[
Assign(
targets=[
List(
elts=[
Name(id='a', ctx=Store()),
Name(id='b', ctx=Store())],
ctx=Store())],
value=List(
elts=[
Constant(value=1),
Constant(value=2.5)],
ctx=Load()))],
type_ignores=[])
b2ecf6b1637e5c3a8f70a584006a582755c7d0ff
9dc80132afb377f585e120fd906fa650aaddbef9
trigger:
row, column = pos
(life.py, line 27)docs for assignment statement in Python here docs for ast.Assign here simple explanation of starred targets here
from ast.Assign docs about assigning to target lists.
If the target list is a single target with no trailing comma, optionally in parentheses, the object is assigned to that target. just assign the type of the value expression to the target
Else:
If the target list contains one target prefixed with an asterisk, called a “starred” target: The object must be an iterable with at least as many items as there are targets in the target list, minus one. The first items of the iterable are assigned, from left to right, to the targets before the starred target. The final items of the iterable are assigned to the targets after the starred target. A list of the remaining items in the iterable is then assigned to the starred target (the list can be empty). - postpone it for LATER, because I have not yet seen so many cases using this
Else: The object must be an iterable with the same number of items as there are targets in the target list, and the items are assigned, from left to right, to the corresponding targets. - RHS has to have the same number of elements as LHS - for every expression
r[index]
on the LHS, assign the type of expressionl[index]
on the RHS**important notes:
str
. so,[a, b] = '12'
is validglobals
is also postponed, see https://github.com/users/andreinaku/projects/2/views/1?pane=issue&itemId=61241366