Skip to content

list

Provide the smallest explicit list-construction and query API that host frontends can target when they need to build list values incrementally or reason about list metadata in lowered control-flow contexts.

Classes:

ListAppend

ListAppend(base: AST, value: AST)

Bases: DataType

Append one value to an existing mutable list variable or field. This node models incremental list growth and is not a user-facing collection API by itself. attributes: base: type: astx.AST value: type: astx.AST type_: type: astx.Int32

Methods:

Source code in packages/astx/src/astx/collections/list.py
139
140
141
142
143
144
145
146
147
148
149
150
151
def __init__(self, base: astx.AST, value: astx.AST) -> None:
    """
    title: Initialize one list append node.
    parameters:
      base:
        type: astx.AST
      value:
        type: astx.AST
    """
    super().__init__()
    self.base = base
    self.value = value
    self.type_ = astx.Int32()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/collections/list.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "ListAppend",
        cast(
            astx.base.ReprStruct,
            {
                "base": self.base.get_struct(simplified),
                "value": self.value.get_struct(simplified),
            },
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ListCreate

ListCreate(element_type: DataType)

Bases: DataType

Methods:

Source code in packages/astx/src/astx/collections/list.py
33
34
35
36
37
38
39
40
41
42
def __init__(self, element_type: astx.DataType) -> None:
    """
    title: Initialize one empty-list constructor.
    parameters:
      element_type:
        type: astx.DataType
    """
    super().__init__()
    self.element_type = element_type
    self.type_ = astx.ListType([element_type])

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/collections/list.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "ListCreate",
        cast(
            astx.base.ReprStruct,
            {"element_type": self.element_type.get_struct(simplified)},
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ListIndex

ListIndex(base: AST, index: AST)

Bases: DataType

Read one element from a list-valued expression using one integer index. attributes: base: type: astx.AST index: type: astx.AST type_: type: astx.DataType

Methods:

Source code in packages/astx/src/astx/collections/list.py
82
83
84
85
86
87
88
89
90
91
92
93
94
def __init__(self, base: astx.AST, index: astx.AST) -> None:
    """
    title: Initialize one list indexing expression.
    parameters:
      base:
        type: astx.AST
      index:
        type: astx.AST
    """
    super().__init__()
    self.base = base
    self.index = index
    self.type_ = AnyType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/collections/list.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "ListIndex",
        cast(
            astx.base.ReprStruct,
            {
                "base": self.base.get_struct(simplified),
                "index": self.index.get_struct(simplified),
            },
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ListLength

ListLength(base: AST)

Bases: DataType

Return the current logical length of one list-valued expression as an int32 value. The runtime stores list lengths as int64, but the current ASTx language-level contract intentionally truncates that representation to Int32. attributes: base: type: astx.AST type_: type: astx.Int32

Methods:

Source code in packages/astx/src/astx/collections/list.py
194
195
196
197
198
199
200
201
202
203
def __init__(self, base: astx.AST) -> None:
    """
    title: Initialize one list length query.
    parameters:
      base:
        type: astx.AST
    """
    super().__init__()
    self.base = base
    self.type_ = astx.Int32()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/collections/list.py
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "ListLength",
        cast(
            astx.base.ReprStruct,
            {"base": self.base.get_struct(simplified)},
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )