andreinaku / SpyType

MIT License
0 stars 0 forks source link

visitor for assignment statement #4

Open andreinaku opened 6 months ago

andreinaku commented 6 months ago

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.

**important notes:

andreinaku commented 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.

andreinaku commented 5 months ago
>>> 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=[])
andreinaku commented 5 months ago

b2ecf6b1637e5c3a8f70a584006a582755c7d0ff

andreinaku commented 5 months ago

9dc80132afb377f585e120fd906fa650aaddbef9