Skip to content

astx

Modules:

Classes:

Functions:

AST

AST(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Methods:

Source code in packages/astx/src/astx/base.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct abstractmethod

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
376
377
378
379
380
381
382
383
384
385
@abstractmethod
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a structure that represents the node object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """

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)
    )

ASTKind

Bases: Enum

ASTNodes

ASTNodes(
    name: str = "entry",
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Generic[ASTType], AST

Methods:

Source code in packages/astx/src/astx/base.py
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
def __init__(
    self,
    name: str = "entry",
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      name:
        type: str
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = name
    self.nodes: list[ASTType] = []
    self.position: int = 0

append

append(value: ASTType) -> None
Source code in packages/astx/src/astx/base.py
484
485
486
487
488
489
490
491
def append(self, value: ASTType) -> None:
    """
    title: Append a new node to the stack.
    parameters:
      value:
        type: ASTType
    """
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    args_nodes = []

    for node in self.nodes:
        args_nodes.append(node.get_struct(simplified))

    key = str(self)
    value = cast(ReprStruct, args_nodes)
    return self._prepare_struct(key, value, 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)
    )

AliasExpr

AliasExpr(
    name: str,
    asname: str = "",
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/packages.py
291
292
293
294
295
296
297
298
299
300
301
def __init__(
    self,
    name: str,
    asname: str = "",
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.name = name
    self.asname = asname
    self.kind = ASTKind.AliasExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the alias.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    str_asname = f", {self.asname}" if self.asname else ""
    str_name_asname = f"[{self.name}{str_asname}]"
    key = f"Alias {str_name_asname}"
    value = ""

    return self._prepare_struct(key, value, 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)
    )

AndOp

AndOp(
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: BoolBinaryOp

Methods:

Source code in packages/astx/src/astx/types/operators.py
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
def __init__(
    self,
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Instantiate AST class for logical AND operation.
    parameters:
      lhs:
        type: DataType
      rhs:
        type: DataType
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(
        op_code=self.op_code,
        lhs=lhs,
        rhs=rhs,
        loc=loc,
        parent=parent,
    )

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/types/operators.py
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"BOOL_BINARY_OP[{self.__class__.__name__}]"
    value: ReprStruct = {
        "lhs": self.lhs.get_struct(simplified),
        "rhs": self.rhs.get_struct(simplified),
    }
    return self._prepare_struct(key, value, 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)
    )

Argument

Argument(
    name: str,
    type_: DataType,
    mutability: MutabilityKind = constant,
    default: Expr = UNDEFINED,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Variable

Methods:

Source code in packages/astx/src/astx/callables.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def __init__(
    self,
    name: str,
    type_: DataType,
    mutability: MutabilityKind = MutabilityKind.constant,
    default: Expr = UNDEFINED,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the VarExprAST instance.
    parameters:
      name:
        type: str
      type_:
        type: DataType
      mutability:
        type: MutabilityKind
      default:
        type: Expr
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(name=name, loc=loc, parent=parent)
    self.mutability = mutability
    self.type_ = type_
    self.default = default
    self.kind = ASTKind.ArgumentKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/callables.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Argument[{self.name}, {self.type_}] = {self.default}"
    value = self.default.get_struct()
    return self._prepare_struct(key, value, 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)
    )

Arguments

Arguments(*args: Argument, **kwargs: Any)

Bases: ASTNodes[Argument]

Methods:

Source code in packages/astx/src/astx/callables.py
117
118
119
120
def __init__(self, *args: Argument, **kwargs: Any) -> None:
    super().__init__(**kwargs)
    for arg in args:
        self.append(arg)

append

append(value: ASTType) -> None
Source code in packages/astx/src/astx/base.py
484
485
486
487
488
489
490
491
def append(self, value: ASTType) -> None:
    """
    title: Append a new node to the stack.
    parameters:
      value:
        type: ASTType
    """
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/callables.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    args_nodes = []

    for node in self.nodes:
        args_nodes.append(node.get_struct(simplified))

    key = str(self)
    value = cast(ReprStruct, args_nodes)
    return self._prepare_struct(key, value, 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)
    )

AssignmentExpr

AssignmentExpr(
    targets: Iterable[Expr] | ASTNodes[Expr],
    value: Expr,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/operators.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def __init__(
    self,
    targets: Iterable[Expr] | ASTNodes[Expr],
    value: Expr,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)

    if isinstance(targets, ASTNodes):
        self.targets = targets
    else:
        self.targets = ASTNodes()
        for target in targets:
            self.targets.append(target)

    self.value = value
    self.kind = ASTKind.AssignmentExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/operators.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "ASSIGNMENT-EXPR"
    targets_dict = {"targets": self.targets.get_struct(simplified)}
    value_dict = {"value": self.value.get_struct(simplified)}

    value = {
        **cast(DictDataTypesStruct, targets_dict),
        **cast(DictDataTypesStruct, value_dict),
    }

    return self._prepare_struct(key, value, 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)
    )

AsyncForRangeLoopExpr

AsyncForRangeLoopExpr(
    variable: InlineVariableDeclaration,
    start: Optional[Expr],
    end: Expr,
    step: Optional[Expr],
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/flows.py
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
def __init__(
    self,
    variable: InlineVariableDeclaration,
    start: Optional[Expr],
    end: Expr,
    step: Optional[Expr],
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the AsyncForRangeLoopExpr instance.
    parameters:
      variable:
        type: InlineVariableDeclaration
      start:
        type: Optional[Expr]
      end:
        type: Expr
      step:
        type: Optional[Expr]
      body:
        type: Block
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.variable = variable
    self.start = start
    self.end = end
    self.step = step
    self.body = body
    self.kind = ASTKind.AsyncRangeLoopExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    for_var = {"var": self.variable.get_struct(simplified)}
    for_start = {
        "start": {}
        if self.start is None
        else self.start.get_struct(simplified)
    }
    for_end = {"end": self.end.get_struct(simplified)}
    for_step = {
        "step": {}
        if self.step is None
        else self.step.get_struct(simplified)
    }
    for_body = self.body.get_struct(simplified)

    key = "ASYNC-FOR-RANGE-LOOP-EXPR"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, for_var),
        **cast(DictDataTypesStruct, for_start),
        **cast(DictDataTypesStruct, for_end),
        **cast(DictDataTypesStruct, for_step),
        **cast(DictDataTypesStruct, for_body),
    }
    return self._prepare_struct(key, value, 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)
    )

AsyncForRangeLoopStmt

AsyncForRangeLoopStmt(
    variable: InlineVariableDeclaration,
    start: Optional[Expr],
    end: Expr,
    step: Optional[Expr],
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/flows.py
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
def __init__(
    self,
    variable: InlineVariableDeclaration,
    start: Optional[Expr],
    end: Expr,
    step: Optional[Expr],
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the AsyncForRangeLoopStmt instance.
    parameters:
      variable:
        type: InlineVariableDeclaration
      start:
        type: Optional[Expr]
      end:
        type: Expr
      step:
        type: Optional[Expr]
      body:
        type: Block
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.variable = variable
    self.start = start
    self.end = end
    self.step = step
    self.body = body
    self.kind = ASTKind.AsyncRangeLoopStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    for_start = {
        "start": {}
        if self.start is None
        else self.start.get_struct(simplified)
    }
    for_end = {"end": self.end.get_struct(simplified)}
    for_step = {
        "step": {}
        if self.step is None
        else self.step.get_struct(simplified)
    }
    for_body = self.body.get_struct(simplified)

    key = "ASYNC-FOR-RANGE-LOOP-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, for_start),
        **cast(DictDataTypesStruct, for_end),
        **cast(DictDataTypesStruct, for_step),
        **cast(DictDataTypesStruct, for_body),
    }
    return self._prepare_struct(key, value, 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)
    )

AugAssign

AugAssign(
    target: Identifier,
    op_code: OpCodeAugAssign,
    value: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: DataType

Methods:

Source code in packages/astx/src/astx/operators.py
268
269
270
271
272
273
274
275
276
277
278
279
def __init__(
    self,
    target: Identifier,
    op_code: OpCodeAugAssign,
    value: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    super().__init__(loc=loc)
    self.target = target
    self.op_code = op_code
    self.value = value
    self.kind = ASTKind.AugmentedAssignKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/operators.py
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = str(self)
    value: ReprStruct = {
        "target": self.target.get_struct(simplified),
        "value": self.value.get_struct(simplified),
    }
    return self._prepare_struct(key, value, 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)
    )

AwaitExpr

AwaitExpr(
    value: Optional[Expr],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/callables.py
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
def __init__(
    self,
    value: Optional[Expr],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the AwaitExpr instance.
    parameters:
      value:
        type: Optional[Expr]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.value = value
    self.kind = ASTKind.AwaitExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/callables.py
646
647
648
649
650
651
652
653
654
655
656
657
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "AWAIT-EXPR"
    value = {} if self.value is None else self.value.get_struct(simplified)
    return self._prepare_struct(key, value, 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)
    )

BinaryOp

BinaryOp(
    op_code: str,
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: DataTypeOps

Methods:

Source code in packages/astx/src/astx/types/operators.py
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
def __init__(
    self,
    op_code: str,
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the BinaryOp instance.
    parameters:
      op_code:
        type: str
      lhs:
        type: DataType
      rhs:
        type: DataType
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)

    self.op_code = op_code
    self.lhs = lhs
    self.rhs = rhs
    self.kind = ASTKind.BinaryOpKind

    if not (
        isinstance(lhs.type_, DataType) and isinstance(rhs.type_, DataType)
    ):
        raise Exception(
            "For now, binary operators are just allowed for `DataType`."
            f"LHS: {lhs.type_}, RHS: {rhs.type_}"
        )

    if lhs.type_ == rhs.type_:
        self.type_ = lhs.type_
    else:
        # type inference
        self.type_ = max([lhs.type_, rhs.type_], key=lambda v: v.nbytes)

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/types/operators.py
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"BINARY[{self.op_code}]"
    lhs = {"lhs": self.lhs.get_struct(simplified)}
    rhs = {"rhs": self.rhs.get_struct(simplified)}

    content: ReprStruct = {**lhs, **rhs}
    return self._prepare_struct(key, content, 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)
    )

Block

Block(
    name: str = "entry",
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: ASTNodes[ASTType]

Methods:

Source code in packages/astx/src/astx/base.py
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
def __init__(
    self,
    name: str = "entry",
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      name:
        type: str
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = name
    self.nodes: list[ASTType] = []
    self.position: int = 0

append

append(value: ASTType) -> None
Source code in packages/astx/src/astx/base.py
484
485
486
487
488
489
490
491
def append(self, value: ASTType) -> None:
    """
    title: Append a new node to the stack.
    parameters:
      value:
        type: ASTType
    """
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/blocks.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    block_nodes = []

    for node in self.nodes:
        block_nodes.append(node.get_struct(simplified))

    key = f"BLOCK[{self.name}-{id(self)}]"
    value = cast(ReprStruct, block_nodes)

    return self._prepare_struct(key, value, 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)
    )

BoolBinaryOp

BoolBinaryOp(
    op_code: str,
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: BinaryOp

Methods:

Source code in packages/astx/src/astx/types/operators.py
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
def __init__(
    self,
    op_code: str,
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(
        op_code=op_code,
        lhs=lhs,
        rhs=rhs,
        loc=loc,
        parent=parent,
    )

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/types/operators.py
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"BOOL_BINARY_OP[{self.__class__.__name__}]"
    value: ReprStruct = {
        "lhs": self.lhs.get_struct(simplified),
        "rhs": self.rhs.get_struct(simplified),
    }
    return self._prepare_struct(key, value, 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)
    )

BoolUnaryOp

BoolUnaryOp(
    op_code: str,
    operand: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: UnaryOp

Methods:

Source code in packages/astx/src/astx/types/operators.py
474
475
476
477
478
479
480
481
482
483
484
485
486
def __init__(
    self,
    op_code: str,
    operand: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(
        op_code=op_code,
        operand=operand,
        loc=loc,
        parent=parent,
    )

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/types/operators.py
496
497
498
499
500
501
502
503
504
505
506
507
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"BOOL_UNARY_OP[{self.__class__.__name__}]"
    value: ReprStruct = {"operand": self.operand.get_struct(simplified)}
    return self._prepare_struct(key, value, 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)
    )

Boolean

Boolean(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: AnyType

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

BreakStmt

BreakStmt(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/flows.py
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the BreakStmt instance.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.kind = ASTKind.BreakStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
852
853
854
855
856
857
858
859
860
861
862
863
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "BREAK-STMT"
    value: DictDataTypesStruct = {}
    return self._prepare_struct(key, value, 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)
    )

CaseStmt

CaseStmt(
    body: Block,
    condition: Optional[Expr] = None,
    default: bool = False,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/flows.py
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
def __init__(
    self,
    body: Block,
    condition: Optional[Expr] = None,
    default: bool = False,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the CaseStmt instance.
    parameters:
      body:
        type: Block
      condition:
        type: Optional[Expr]
      default:
        type: bool
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.condition = condition
    self.body = body
    self.default = default
    self.kind = ASTKind.CaseStmtKind

    if self.default is False and self.condition is None:
        raise ValueError(
            "Condition must be provided for non-default branches."
        )

    if self.default is True and self.condition is not None:
        raise ValueError(
            "Condition must NOT be provided for default branches."
        )

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    default_case = "default" if self.condition is None else ""
    default_only = "[default]" if self.condition is None else ""
    id_str = f"{id(self)}" if simplified else ""

    key = (
        f"CASE-STMT[{id_str}{default_case}]"
        if simplified and self.condition is not None
        else f"CASE-STMT[{id_str}, {default_case}]"
        if simplified
        else f"CASE-STMT{default_only}"
    )

    condition_dict = (
        {}
        if self.condition is None
        else {"condition": self.condition.get_struct(simplified)}
    )
    value = {
        **cast(DictDataTypesStruct, condition_dict),
        "body": self.body.get_struct(simplified),
    }
    return self._prepare_struct(key, value, 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)
    )

CatchHandlerStmt

CatchHandlerStmt(
    body: Block[AST],
    name: Optional[Identifier] = None,
    types: Optional[
        Iterable[Identifier] | ASTNodes[Identifier]
    ] = None,
    parent: Optional[ASTNodes] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/exceptions.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
def __init__(
    self,
    body: Block[AST],
    name: Optional[Identifier] = None,
    types: Optional[Iterable[Identifier] | ASTNodes[Identifier]] = None,
    parent: Optional[ASTNodes] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the instance.
    parameters:
      body:
        type: Block[AST]
      name:
        type: Optional[Identifier]
      types:
        type: Optional[Iterable[Identifier] | ASTNodes[Identifier]]
      parent:
        type: Optional[ASTNodes]
      loc:
        type: SourceLocation
    """
    super().__init__(loc=loc, parent=parent)
    self.body = body
    self.name = name

    if types:
        if isinstance(types, ASTNodes):
            self.types = types
        else:
            self.types = ASTNodes[Identifier]()
            for t in types:
                self.types.append(t)
    else:
        self.types = None

    self.kind = ASTKind.CatchHandlerStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/exceptions.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = (
        f"CATCH-HANDLER-STMT[{id(self)}]"
        if simplified
        else "CATCH-HANDLER-STMT"
    )
    body_dict = {"body": self.body.get_struct(simplified)}
    name_dict = (
        {"name": self.name.get_struct(simplified)} if self.name else {}
    )
    types_dict = (
        {"types": self.types.get_struct(simplified)} if self.types else {}
    )

    value: DictDataTypesStruct = {
        **cast(DictDataTypesStruct, body_dict),
        **cast(DictDataTypesStruct, name_dict),
        **cast(DictDataTypesStruct, types_dict),
    }
    return self._prepare_struct(key, value, 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)
    )

ClassDeclStmt

ClassDeclStmt(
    name: str,
    bases: Iterable[Expr] | ASTNodes[Expr] = [],
    decorators: Iterable[Expr] | ASTNodes[Expr] = [],
    visibility: VisibilityKind = public,
    is_abstract: bool = False,
    metaclass: Optional[Expr] = None,
    attributes: Iterable[VariableDeclaration]
    | ASTNodes[VariableDeclaration] = [],
    methods: Iterable[FunctionDef]
    | ASTNodes[FunctionDef] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/classes.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def __init__(
    self,
    name: str,
    bases: Iterable[Expr] | ASTNodes[Expr] = [],
    decorators: Iterable[Expr] | ASTNodes[Expr] = [],
    visibility: VisibilityKind = VisibilityKind.public,
    is_abstract: bool = False,
    metaclass: Optional[Expr] = None,
    attributes: Iterable[VariableDeclaration]
    | ASTNodes[VariableDeclaration] = [],
    methods: Iterable[FunctionDef] | ASTNodes[FunctionDef] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize ClassDeclStmt instance.
    parameters:
      name:
        type: str
      bases:
        type: Iterable[Expr] | ASTNodes[Expr]
      decorators:
        type: Iterable[Expr] | ASTNodes[Expr]
      visibility:
        type: VisibilityKind
      is_abstract:
        type: bool
      metaclass:
        type: Optional[Expr]
      attributes:
        type: Iterable[VariableDeclaration] | ASTNodes[VariableDeclaration]
      methods:
        type: Iterable[FunctionDef] | ASTNodes[FunctionDef]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = name

    if isinstance(bases, ASTNodes):
        self.bases = bases
    else:
        self.bases = ASTNodes()
        for base in bases:
            self.bases.append(base)

    if isinstance(decorators, ASTNodes):
        self.decorators = decorators
    else:
        self.decorators = ASTNodes[Expr]()
        for decorator in decorators:
            self.decorators.append(decorator)

    if isinstance(attributes, ASTNodes):
        self.attributes = attributes
    else:
        self.attributes = ASTNodes[VariableDeclaration]()
        for a in attributes:
            self.attributes.append(a)

    if isinstance(methods, ASTNodes):
        self.methods = methods
    else:
        self.methods = ASTNodes[FunctionDef]()
        for m in methods:
            self.methods.append(m)

    self.visibility = visibility
    self.is_abstract = is_abstract
    self.metaclass = metaclass
    self.kind = ASTKind.ClassDeclStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/classes.py
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    vis = dict(zip(("public", "private", "protected"), ("+", "-", "#")))
    abstract = ", abstract" if self.is_abstract else ""

    key = f"CLASS-DECL[{vis[self.visibility.name]}{self.name}{abstract}]"
    value = self._get_struct_wrapper(simplified)

    return self._prepare_struct(key, value, 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)
    )

ClassDefStmt

ClassDefStmt(
    name: str,
    bases: Iterable[Expr] | ASTNodes[Expr] = [],
    decorators: Iterable[Expr] | ASTNodes[Expr] = [],
    body: Block = CLASS_BODY_DEFAULT,
    visibility: VisibilityKind = public,
    is_abstract: bool = False,
    metaclass: Optional[Expr] = None,
    attributes: Iterable[VariableDeclaration]
    | ASTNodes[VariableDeclaration] = [],
    methods: Iterable[FunctionDef]
    | ASTNodes[FunctionDef] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: ClassDeclStmt

Methods:

Source code in packages/astx/src/astx/classes.py
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
def __init__(
    self,
    name: str,
    bases: Iterable[Expr] | ASTNodes[Expr] = [],
    decorators: Iterable[Expr] | ASTNodes[Expr] = [],
    body: Block = CLASS_BODY_DEFAULT,
    visibility: VisibilityKind = VisibilityKind.public,
    is_abstract: bool = False,
    metaclass: Optional[Expr] = None,
    attributes: Iterable[VariableDeclaration]
    | ASTNodes[VariableDeclaration] = [],
    methods: Iterable[FunctionDef] | ASTNodes[FunctionDef] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize ClassDefStmt instance.
    parameters:
      name:
        type: str
      bases:
        type: Iterable[Expr] | ASTNodes[Expr]
      decorators:
        type: Iterable[Expr] | ASTNodes[Expr]
      body:
        type: Block
      visibility:
        type: VisibilityKind
      is_abstract:
        type: bool
      metaclass:
        type: Optional[Expr]
      attributes:
        type: Iterable[VariableDeclaration] | ASTNodes[VariableDeclaration]
      methods:
        type: Iterable[FunctionDef] | ASTNodes[FunctionDef]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(
        name=name,
        bases=bases,
        decorators=decorators,
        visibility=visibility,
        is_abstract=is_abstract,
        metaclass=metaclass,
        attributes=attributes,
        methods=methods,
        loc=loc,
        parent=parent,
    )

    if body != CLASS_BODY_DEFAULT:
        self.body = body
    else:
        self.body = copy.deepcopy(body)
        self.body.name = f"{name}_body"
    self.kind = ASTKind.ClassDefStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/classes.py
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    vis = dict(zip(("public", "private", "protected"), ("+", "-", "#")))
    abstract = ", abstract" if self.is_abstract else ""

    key = f"CLASS-DEF[{vis[self.visibility.name]}{self.name}{abstract}]"
    value = self._get_struct_wrapper(simplified)

    if self.body != CLASS_BODY_DEFAULT:
        value["body"] = self.body.get_struct(simplified)

    return self._prepare_struct(key, value, 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)
    )

CollectionType

CollectionType(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: AnyType

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

CompareOp

CompareOp(
    left: DataType,
    ops: Iterable[
        Literal["==", "!=", "<", ">", "<=", ">="]
    ],
    comparators: Iterable[DataType],
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: DataType

Methods:

Source code in packages/astx/src/astx/operators.py
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
def __init__(
    self,
    left: DataType,
    ops: Iterable[Literal["==", "!=", "<", ">", "<=", ">="]],
    comparators: Iterable[DataType],
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the CompareOp instance.
    parameters:
      left:
        type: DataType
      ops:
        type: Iterable[Literal[==, !=, <, >, <=, >=]]
      comparators:
        type: Iterable[DataType]
      loc:
        type: SourceLocation
    """
    super().__init__(loc=loc)
    self.ops = list(ops)
    self.comparators = list(comparators)
    if len(self.ops) != len(self.comparators):
        raise ValueError(
            "Number of operators must equal number of comparators."
        )
    for op in self.ops:
        if op not in ["==", "!=", "<", ">", "<=", ">="]:
            raise ValueError(f"Invalid comparison operator: {op}")
    self.left = left
    self.kind = ASTKind.CompareOpKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/operators.py
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    ops_str = ", ".join(self.ops)
    key = f"COMPARE[{ops_str}]"
    content: ReprStruct = {
        "left": self.left.get_struct(simplified),
        "comparators": [
            comp.get_struct(simplified) for comp in self.comparators
        ],
    }
    return self._prepare_struct(key, content, 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)
    )

Complex

Complex(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Number

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Complex32

Complex32(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Complex

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Complex64

Complex64(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Complex

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Comprehension

Comprehension(
    generators: Iterable[ComprehensionClause]
    | ASTNodes[ComprehensionClause],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/comprehensions.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def __init__(
    self,
    generators: (
        Iterable[ComprehensionClause] | ASTNodes[ComprehensionClause]
    ),
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)

    if isinstance(generators, ASTNodes):
        self.generators = generators
    elif isinstance(generators, Iterable):
        self.generators = ASTNodes[ComprehensionClause]()
        for generator in generators:
            self.generators.append(generator)

get_struct abstractmethod

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/comprehensions.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
@abstractmethod
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    value: ReprStruct = {
        "generators": self.generators.get_struct(simplified),
    }
    key = f"{self}" if not simplified else f"{self}#{id(self)}"
    return self._prepare_struct(key, value, 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)
    )

ComprehensionClause

ComprehensionClause(
    target: Expr,
    iterable: Expr,
    conditions: Optional[
        Iterable[Expr] | ASTNodes[Expr]
    ] = None,
    is_async: bool = False,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/comprehensions.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def __init__(
    self,
    target: Expr,
    iterable: Expr,
    conditions: Optional[Iterable[Expr] | ASTNodes[Expr]] = None,
    is_async: bool = False,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.target = target
    self.iterable = iterable
    self.is_async = is_async
    self.kind = ASTKind.ComprehensionKind

    if isinstance(conditions, ASTNodes):
        self.conditions = conditions
    elif isinstance(conditions, Iterable):
        self.conditions = ASTNodes()
        for condition in conditions:
            self.conditions.append(condition)
    else:
        self.conditions = ASTNodes[Expr]()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/comprehensions.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    conditions = (
        {"conditions": self.conditions.get_struct(simplified)}
        if self.conditions.nodes
        else {}
    )

    value: ReprStruct = {
        "target": self.target.get_struct(simplified),
        "iterable": self.iterable.get_struct(simplified),
        **conditions,
    }

    key = f"{self}" if not simplified else f"{self}#{id(self)}"
    return self._prepare_struct(key, value, 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)
    )

ContinueStmt

ContinueStmt(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/flows.py
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the ContinueStmt instance.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.kind = ASTKind.ContinueStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
902
903
904
905
906
907
908
909
910
911
912
913
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "CONTINUE-STMT"
    value: DictDataTypesStruct = {}
    return self._prepare_struct(key, value, 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)
    )

DataType

DataType(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: ExprType

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

DataTypeOps

DataTypeOps(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: DataType

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Date

Date(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Temporal

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

DateTime

DateTime(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Temporal

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

DeleteStmt

DeleteStmt(
    value: Iterable[Identifier],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/data.py
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def __init__(
    self,
    value: Iterable[Identifier],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the DeleteStmt instance.
    parameters:
      value:
        type: Iterable[Identifier]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.value = value
    self.kind = ASTKind.DeleteStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/data.py
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "DELETE"

    value: ReprStruct = {
        f"target_{i}": val.get_struct(simplified)
        for i, val in enumerate(self.value)
    }

    return self._prepare_struct(key, value, 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)
    )

DictType

DictType(key_type: ExprType, value_type: ExprType)

Bases: CollectionType

Methods:

Source code in packages/astx/src/astx/types/collections.py
 98
 99
100
101
102
103
104
105
106
107
108
def __init__(self, key_type: ExprType, value_type: ExprType) -> None:
    """
    title: Initialize DictType with key-value types.
    parameters:
      key_type:
        type: ExprType
      value_type:
        type: ExprType
    """
    self.key_type = key_type
    self.value_type = value_type

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

DoWhileExpr

DoWhileExpr(
    condition: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: WhileExpr

Methods:

Source code in packages/astx/src/astx/flows.py
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
def __init__(
    self,
    condition: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the DoWhileExpr instance.
    parameters:
      condition:
        type: Expr
      body:
        type: Block
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(
        condition=condition, body=body, loc=loc, parent=parent
    )
    self.kind = ASTKind.DoWhileExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    while_condition = self.condition.get_struct(simplified)
    while_body = self.body.get_struct(simplified)

    key = "WHILE-EXPR"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, while_condition),
        **cast(DictDataTypesStruct, while_body),
    }

    return self._prepare_struct(key, value, 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)
    )

DoWhileStmt

DoWhileStmt(
    condition: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: WhileStmt

Methods:

Source code in packages/astx/src/astx/flows.py
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
def __init__(
    self,
    condition: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the DoWhileStmt instance.
    parameters:
      condition:
        type: Expr
      body:
        type: Block
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(
        condition=condition, body=body, loc=loc, parent=parent
    )
    self.kind = ASTKind.DoWhileStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    while_condition = self.condition.get_struct(simplified)
    while_body = self.body.get_struct(simplified)

    key = f"WHILE-STMT[{id(self)}]" if simplified else "WHILE-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, while_condition),
        **cast(DictDataTypesStruct, while_body),
    }

    return self._prepare_struct(key, value, 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)
    )

Ellipsis

Ellipsis(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/subscript.py
191
192
193
194
195
196
197
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.kind = ASTKind.EllipsisKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/subscript.py
199
200
201
202
203
204
205
206
207
208
209
210
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = str(self)
    value: DictDataTypesStruct = {}
    return self._prepare_struct(key, value, 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)
    )

EnumDeclStmt

EnumDeclStmt(
    name: str,
    attributes: Iterable[VariableDeclaration]
    | ASTNodes[VariableDeclaration] = [],
    visibility: VisibilityKind = public,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/classes.py
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
def __init__(
    self,
    name: str,
    attributes: Iterable[VariableDeclaration]
    | ASTNodes[VariableDeclaration] = [],
    visibility: VisibilityKind = VisibilityKind.public,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize EnumDeclStmt instance.
    parameters:
      name:
        type: str
      attributes:
        type: Iterable[VariableDeclaration] | ASTNodes[VariableDeclaration]
      visibility:
        type: VisibilityKind
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = name

    if isinstance(attributes, ASTNodes):
        self.attributes = attributes
    else:
        self.attributes = ASTNodes[VariableDeclaration]()
        for a in attributes:
            self.attributes.append(a)

    self.visibility = visibility
    self.kind = ASTKind.EnumDeclStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/classes.py
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    vis = dict(zip(("public", "private", "protected"), ("+", "-", "#")))
    key = f"ENUM-DECL[{vis[self.visibility.name]}{self.name}]"

    attrs_dict: ReprStruct = {}
    if self.attributes:
        attrs_dict = {"attributes": self.attributes.get_struct(simplified)}

    value = {
        **cast(DictDataTypesStruct, attrs_dict),
    }
    return self._prepare_struct(key, value, 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)
    )

ExceptionHandlerStmt

ExceptionHandlerStmt(
    body: Block[AST],
    handlers: Iterable[CatchHandlerStmt]
    | ASTNodes[CatchHandlerStmt],
    finally_handler: Optional[FinallyHandlerStmt] = None,
    parent: Optional[ASTNodes] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/exceptions.py
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
def __init__(
    self,
    body: Block[AST],
    handlers: Iterable[CatchHandlerStmt] | ASTNodes[CatchHandlerStmt],
    finally_handler: Optional[FinallyHandlerStmt] = None,
    parent: Optional[ASTNodes] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the instance.
    parameters:
      body:
        type: Block[AST]
      handlers:
        type: Iterable[CatchHandlerStmt] | ASTNodes[CatchHandlerStmt]
      finally_handler:
        type: Optional[FinallyHandlerStmt]
      parent:
        type: Optional[ASTNodes]
      loc:
        type: SourceLocation
    """
    super().__init__(loc=loc, parent=parent)
    self.body = body

    if isinstance(handlers, ASTNodes):
        self.handlers = handlers
    else:
        self.handlers = ASTNodes[CatchHandlerStmt]()
        for h in handlers:
            self.handlers.append(h)

    self.finally_handler = finally_handler

    self.kind = ASTKind.ExceptionHandlerStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/exceptions.py
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = (
        f"EXCEPTION-HANDLER-STMT[{id(self)}]"
        if simplified
        else "EXCEPTION-HANDLER-STMT"
    )

    body_dict = {"body": self.body.get_struct(simplified)}
    handlers_dict = {"handlers": self.handlers.get_struct(simplified)}
    finally_dict = (
        {"finally_handler": self.finally_handler.get_struct(simplified)}
        if self.finally_handler
        else {}
    )

    value: DictDataTypesStruct = {
        **cast(DictDataTypesStruct, body_dict),
        **cast(DictDataTypesStruct, handlers_dict),
        **cast(DictDataTypesStruct, finally_dict),
    }
    return self._prepare_struct(key, value, 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)
    )

Expr

Expr(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: AST

Methods:

Source code in packages/astx/src/astx/base.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct abstractmethod

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
376
377
378
379
380
381
382
383
384
385
@abstractmethod
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a structure that represents the node object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """

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)
    )

ExprType

ExprType(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/base.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
576
577
578
579
580
581
582
583
584
585
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a structure that represents the node object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    return {"Type": self.__class__.__name__}

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)
    )

FinallyHandlerStmt

FinallyHandlerStmt(
    body: Block[AST],
    parent: Optional[ASTNodes] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/exceptions.py
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
def __init__(
    self,
    body: Block[AST],
    parent: Optional[ASTNodes] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the instance.
    parameters:
      body:
        type: Block[AST]
      parent:
        type: Optional[ASTNodes]
      loc:
        type: SourceLocation
    """
    super().__init__(loc=loc, parent=parent)
    self.body = body
    self.kind = ASTKind.FinallyHandlerStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/exceptions.py
327
328
329
330
331
332
333
334
335
336
337
338
339
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"FINALLY-STMT[{id(self)}]" if simplified else "FINALLY-STMT"
    value: DictDataTypesStruct = {"body": self.body.get_struct(simplified)}

    return self._prepare_struct(key, value, 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)
    )

Float16

Float16(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Floating

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Float32

Float32(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Floating

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Float64

Float64(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Floating

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Floating

Floating(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Number

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

ForCountLoopExpr

ForCountLoopExpr(
    initializer: InlineVariableDeclaration,
    condition: Expr,
    update: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

This is a very basic for loop, used by languages like C or C++. attributes: kind: type: ASTKind initializer: type: InlineVariableDeclaration condition: type: Expr update: type: Expr body: type: Block

Methods:

Source code in packages/astx/src/astx/flows.py
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
def __init__(
    self,
    initializer: InlineVariableDeclaration,
    condition: Expr,
    update: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the ForLoopCountExpr instance.
    parameters:
      initializer:
        type: InlineVariableDeclaration
      condition:
        type: Expr
      update:
        type: Expr
      body:
        type: Block
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.initializer = initializer
    self.condition = condition
    self.update = update
    self.body = body
    self.kind = ASTKind.ForCountLoopExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    for_init = {"initialization": self.initializer.get_struct(simplified)}
    for_cond = {"condition": self.condition.get_struct(simplified)}
    for_update = {"update": self.update.get_struct(simplified)}
    for_body = self.body.get_struct(simplified)

    key = "FOR-COUNT-EXPR"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, for_init),
        **cast(DictDataTypesStruct, for_cond),
        **cast(DictDataTypesStruct, for_update),
        **cast(DictDataTypesStruct, for_body),
    }
    return self._prepare_struct(key, value, 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)
    )

ForCountLoopStmt

ForCountLoopStmt(
    initializer: InlineVariableDeclaration,
    condition: Expr,
    update: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

This is a very basic for loop, used by languages like C or C++. attributes: kind: type: ASTKind initializer: type: InlineVariableDeclaration condition: type: Expr update: type: Expr body: type: Block

Methods:

Source code in packages/astx/src/astx/flows.py
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
def __init__(
    self,
    initializer: InlineVariableDeclaration,
    condition: Expr,
    update: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the ForCountLoopStmt instance.
    parameters:
      initializer:
        type: InlineVariableDeclaration
      condition:
        type: Expr
      update:
        type: Expr
      body:
        type: Block
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.initializer = initializer
    self.condition = condition
    self.update = update
    self.body = body
    self.kind = ASTKind.ForCountLoopStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    for_init = {"initialization": self.initializer.get_struct(simplified)}
    for_cond = {"condition": self.condition.get_struct(simplified)}
    for_update = {"update": self.update.get_struct(simplified)}
    for_body = self.body.get_struct(simplified)

    key = f"FOR-COUNT-STMT[{id(self)}]" if simplified else "FOR-COUNT-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, for_init),
        **cast(DictDataTypesStruct, for_cond),
        **cast(DictDataTypesStruct, for_update),
        **cast(DictDataTypesStruct, for_body),
    }

    return self._prepare_struct(key, value, 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)
    )

ForRangeLoopExpr

ForRangeLoopExpr(
    variable: InlineVariableDeclaration,
    start: Expr,
    end: Expr,
    step: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/flows.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
def __init__(
    self,
    variable: InlineVariableDeclaration,
    start: Expr,
    end: Expr,
    step: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the ForRangeLoopExpr instance.
    parameters:
      variable:
        type: InlineVariableDeclaration
      start:
        type: Expr
      end:
        type: Expr
      step:
        type: Expr
      body:
        type: Block
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.variable = variable
    self.start = start
    self.end = end
    self.step = step
    self.body = body
    self.kind = ASTKind.ForRangeLoopExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    for_var = {"var": self.variable.get_struct(simplified)}
    for_start = {"start": self.start.get_struct(simplified)}
    for_end = {"end": self.end.get_struct(simplified)}
    for_step = {"step": self.step.get_struct(simplified)}
    for_body = self.body.get_struct(simplified)

    key = "FOR-RANGE-LOOP-EXPR"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, for_var),
        **cast(DictDataTypesStruct, for_start),
        **cast(DictDataTypesStruct, for_end),
        **cast(DictDataTypesStruct, for_step),
        **cast(DictDataTypesStruct, for_body),
    }
    return self._prepare_struct(key, value, 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)
    )

ForRangeLoopStmt

ForRangeLoopStmt(
    variable: InlineVariableDeclaration,
    start: Expr,
    end: Expr,
    step: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/flows.py
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
def __init__(
    self,
    variable: InlineVariableDeclaration,
    start: Expr,
    end: Expr,
    step: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the ForRangeLoopStmt instance.
    parameters:
      variable:
        type: InlineVariableDeclaration
      start:
        type: Expr
      end:
        type: Expr
      step:
        type: Expr
      body:
        type: Block
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.variable = variable
    self.start = start
    self.end = end
    self.step = step
    self.body = body
    self.kind = ASTKind.ForRangeLoopStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    for_start = {"start": self.start.get_struct(simplified)}
    for_end = {"end": self.end.get_struct(simplified)}
    for_step = {"step": self.step.get_struct(simplified)}
    for_body = self.body.get_struct(simplified)

    key = (
        f"FOR-RANGE-LOOP-STMT[{id(self)}]"
        if simplified
        else "FOR-RANGE-LOOP-STMT"
    )
    value: ReprStruct = {
        **cast(DictDataTypesStruct, for_start),
        **cast(DictDataTypesStruct, for_end),
        **cast(DictDataTypesStruct, for_step),
        **cast(DictDataTypesStruct, for_body),
    }
    return self._prepare_struct(key, value, 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)
    )

FunctionAsyncDef

FunctionAsyncDef(
    prototype: FunctionPrototype,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: FunctionDef

Methods:

Attributes:

Source code in packages/astx/src/astx/callables.py
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
def __init__(
    self,
    prototype: FunctionPrototype,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the FunctionAsync instance.
    parameters:
      prototype:
        type: FunctionPrototype
      body:
        type: Block
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(
        loc=loc, parent=parent, body=body, prototype=prototype
    )
    self.kind = ASTKind.FunctionAsyncDefKind

name property

name: str

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/callables.py
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Get the AST structure that represent the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    fn_args = self.prototype.args.get_struct(simplified)
    fn_body = self.body.get_struct(simplified)

    key = f"FUNCTIONASYNC-DEF[{self.prototype.name}]"
    args_struct = {"args": fn_args}
    body_struct = {"body": fn_body}

    value: ReprStruct = {**args_struct, **body_struct}
    return self._prepare_struct(key, value, 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)
    )

FunctionCall

FunctionCall(
    fn: FunctionDef | str,
    args: Iterable[DataType],
    type_: DataType = AnyType(),
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: DataType

Methods:

Source code in packages/astx/src/astx/callables.py
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
def __init__(
    self,
    fn: FunctionDef | str,
    args: Iterable[DataType],
    type_: DataType = AnyType(),
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the Call instance.
    parameters:
      fn:
        type: FunctionDef | str
      args:
        type: Iterable[DataType]
      type_:
        type: DataType
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.fn = fn if not isinstance(fn, FunctionDef) else fn.name
    self.args = args
    self.kind = ASTKind.CallKind
    self.type_ = type_

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/callables.py
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    call_params = []

    for node in self.args:
        call_params.append(node.get_struct(simplified))

    key = f"FUNCTION-CALL[{self.fn}]"
    value = cast(
        ReprStruct,
        {
            f"Parameters ({len(call_params)})": {
                f"param({idx})": param
                for idx, param in enumerate(call_params)
            }
        },
    )

    return self._prepare_struct(key, value, 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)
    )

FunctionDef

FunctionDef(
    prototype: FunctionPrototype,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Attributes:

Source code in packages/astx/src/astx/callables.py
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
def __init__(
    self,
    prototype: FunctionPrototype,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the Function instance.
    parameters:
      prototype:
        type: FunctionPrototype
      body:
        type: Block
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.prototype = prototype
    self.body = body
    self.kind = ASTKind.FunctionDefKind

name property

name: str

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/callables.py
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Get the AST structure that represent the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    fn_args = self.prototype.args.get_struct(simplified)
    fn_body = self.body.get_struct(simplified)

    key = f"FUNCTION-DEF[{self.prototype.name}]"
    args_struct = {"args": fn_args}
    body_struct = {"body": fn_body}

    value: ReprStruct = {**args_struct, **body_struct}
    return self._prepare_struct(key, value, 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)
    )

FunctionPrototype

FunctionPrototype(
    name: str,
    args: Arguments,
    return_type: AnyType,
    scope: ScopeKind = global_,
    visibility: VisibilityKind = public,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/callables.py
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
def __init__(
    self,
    name: str,
    args: Arguments,
    return_type: AnyType,
    scope: ScopeKind = ScopeKind.global_,
    visibility: VisibilityKind = VisibilityKind.public,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the FunctionPrototype instance.
    parameters:
      name:
        type: str
      args:
        type: Arguments
      return_type:
        type: AnyType
      scope:
        type: ScopeKind
      visibility:
        type: VisibilityKind
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = name
    self.args = args
    self.return_type = return_type
    self.loc = loc
    self.kind = ASTKind.PrototypeKind
    self.scope = scope
    self.visibility = visibility

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/callables.py
304
305
306
307
308
309
310
311
312
313
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Get the AST structure that represent the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    raise Exception("Visitor method not necessary")

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)
    )

FunctionReturn

FunctionReturn(
    value: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/callables.py
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
def __init__(
    self,
    value: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the Return instance.
    parameters:
      value:
        type: DataType
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.value = value
    self.kind = ASTKind.ReturnKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/callables.py
360
361
362
363
364
365
366
367
368
369
370
371
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "RETURN"
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, 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)
    )

GeneratorExpr

GeneratorExpr(
    element: Expr,
    generators: Iterable[ComprehensionClause]
    | ASTNodes[ComprehensionClause],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Comprehension

Methods:

Source code in packages/astx/src/astx/comprehensions.py
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
def __init__(
    self,
    element: Expr,
    generators: Iterable[ComprehensionClause]
    | ASTNodes[ComprehensionClause],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the GeneratorExpr instance.
    parameters:
      element:
        type: Expr
      generators:
        type: Iterable[ComprehensionClause] | ASTNodes[ComprehensionClause]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(generators=generators, loc=loc, parent=parent)
    self.element = element
    self.kind = ASTKind.GeneratorExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/comprehensions.py
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"GENERATOR-EXPR#{id(self)}" if simplified else "GENERATOR-EXPR"
    value: ReprStruct = {
        "element": self.element.get_struct(simplified),
        "generators": self.generators.get_struct(simplified),
    }
    return self._prepare_struct(key, value, 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)
    )

GotoStmt

GotoStmt(
    label: Identifier,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/flows.py
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
def __init__(
    self,
    label: Identifier,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the Return instance.
    parameters:
      label:
        type: Identifier
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.label = label
    self.kind = ASTKind.GotoStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"GOTO-STMT[{self.label.name}]"
    value: DictDataTypesStruct = {}
    return self._prepare_struct(key, value, 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)
    )

Identifier

Identifier(
    name: str,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: DataTypeOps

Methods:

Source code in packages/astx/src/astx/data.py
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
def __init__(
    self,
    name: str,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the Identifier instance.
    parameters:
      name:
        type: str
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = name
    # note: necessary for data operations
    self.type_ = AnyType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/data.py
265
266
267
268
269
270
271
272
273
274
275
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a structure that represents the Identifier object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"{self.__class__.__name__.upper()}[{self.name}]"
    return self._prepare_struct(key, self.name, 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)
    )

IfExpr

IfExpr(
    condition: Expr,
    then: Block,
    else_: Optional[Block] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/flows.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
def __init__(
    self,
    condition: Expr,
    then: Block,
    else_: Optional[Block] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the IfExpr instance.
    parameters:
      condition:
        type: Expr
      then:
        type: Block
      else_:
        type: Optional[Block]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.loc = loc
    self.condition = condition
    self.then = then
    self.else_ = else_
    self.kind = ASTKind.IfExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    if_condition = {"condition": self.condition.get_struct(simplified)}
    if_then = {"then-block": self.then.get_struct(simplified)}
    if_else: ReprStruct = {}

    if self.else_ is not None:
        if_else = {"else-block": self.else_.get_struct(simplified)}

    key = "IF-EXPR"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, if_condition),
        **cast(DictDataTypesStruct, if_then),
        **cast(DictDataTypesStruct, if_else),
    }

    return self._prepare_struct(key, value, 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)
    )

IfStmt

IfStmt(
    condition: Expr,
    then: Block,
    else_: Optional[Block] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/flows.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def __init__(
    self,
    condition: Expr,
    then: Block,
    else_: Optional[Block] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the IfStmt instance.
    parameters:
      condition:
        type: Expr
      then:
        type: Block
      else_:
        type: Optional[Block]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.loc = loc
    self.condition = condition
    self.then = then
    self.else_ = else_
    self.kind = ASTKind.IfStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    if_condition = {"condition": self.condition.get_struct(simplified)}
    if_then = {"then-block": self.then.get_struct(simplified)}
    if_else: ReprStruct = {}

    if self.else_ is not None:
        if_else = {"else-block": self.else_.get_struct(simplified)}

    key = f"IF-STMT[{id(self)}]" if simplified else "IF-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, if_condition),
        **cast(DictDataTypesStruct, if_then),
        **cast(DictDataTypesStruct, if_else),
    }

    return self._prepare_struct(key, value, 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)
    )

ImportExpr

ImportExpr(
    names: list[AliasExpr],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/packages.py
469
470
471
472
473
474
475
476
477
def __init__(
    self,
    names: list[AliasExpr],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.names = names
    self.kind = ASTKind.ImportExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
488
489
490
491
492
493
494
495
496
497
498
499
500
501
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the import expression.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "ImportExpr"
    value = cast(
        ReprStruct, [name.get_struct(simplified) for name in self.names]
    )
    return self._prepare_struct(key, value, 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)
    )

ImportFromExpr

ImportFromExpr(
    names: list[AliasExpr],
    module: str = "",
    level: int = 0,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/packages.py
526
527
528
529
530
531
532
533
534
535
536
537
538
def __init__(
    self,
    names: list[AliasExpr],
    module: str = "",
    level: int = 0,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.names = names
    self.module = module
    self.level = level
    self.kind = ASTKind.ImportFromExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the import-from expression.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    level_dots = "." * self.level
    module_str = (
        f"{level_dots}{self.module}" if self.module else level_dots
    )

    key = f"ImportFromExpr [{module_str}]"
    value = cast(
        ReprStruct, [name.get_struct(simplified) for name in self.names]
    )

    return self._prepare_struct(key, value, 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)
    )

ImportFromStmt

ImportFromStmt(
    names: list[AliasExpr],
    module: str = "",
    level: int = 0,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/packages.py
404
405
406
407
408
409
410
411
412
413
414
415
416
def __init__(
    self,
    names: list[AliasExpr],
    module: str = "",
    level: int = 0,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.module = module
    self.names = names
    self.level = level
    self.kind = ASTKind.ImportFromStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the import-from statement.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    level_dots = "." * self.level
    module_str = (
        f"{level_dots}{self.module}" if self.module else level_dots
    )

    key = f"ImportFromStmt [{module_str}]"
    value = cast(
        ReprStruct, [name.get_struct(simplified) for name in self.names]
    )

    return self._prepare_struct(key, value, 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)
    )

ImportStmt

ImportStmt(
    names: list[AliasExpr],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/packages.py
347
348
349
350
351
352
353
354
355
def __init__(
    self,
    names: list[AliasExpr],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.names = names
    self.kind = ASTKind.ImportStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
366
367
368
369
370
371
372
373
374
375
376
377
378
379
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the import statement.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "ImportStmt"
    value = cast(
        ReprStruct, [name.get_struct(simplified) for name in self.names]
    )
    return self._prepare_struct(key, value, 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)
    )

InlineVariableDeclaration

InlineVariableDeclaration(
    name: str,
    type_: DataType,
    mutability: MutabilityKind = constant,
    visibility: VisibilityKind = public,
    scope: ScopeKind = local,
    value: Expr = UNDEFINED,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Can be used in expressions like for loops. attributes: scope: type: ScopeKind visibility: type: VisibilityKind kind: type: ASTKind mutability: type: MutabilityKind name: type: str type_: type: DataType value: type: Expr

Methods:

Source code in packages/astx/src/astx/data.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
def __init__(
    self,
    name: str,
    type_: DataType,
    mutability: MutabilityKind = MutabilityKind.constant,
    visibility: VisibilityKind = VisibilityKind.public,
    scope: ScopeKind = ScopeKind.local,
    value: Expr = UNDEFINED,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the VarExprAST instance.
    parameters:
      name:
        type: str
      type_:
        type: DataType
      mutability:
        type: MutabilityKind
      visibility:
        type: VisibilityKind
      scope:
        type: ScopeKind
      value:
        type: Expr
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.mutability = mutability
    self.scope = scope
    self.visibility = visibility
    self.name = name
    self.type_ = type_
    self.value = value
    self.kind = ASTKind.VarDeclKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/data.py
207
208
209
210
211
212
213
214
215
216
217
218
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = str(self)
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, 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)
    )

Int16

Int16(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: SignedInteger

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Int32

Int32(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: SignedInteger

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Int64

Int64(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: SignedInteger

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Int8

Int8(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: SignedInteger

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Integer

Integer(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: AnyType

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

LambdaExpr

LambdaExpr(
    body: Expr,
    params: Arguments = Arguments(),
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/callables.py
493
494
495
496
497
498
499
500
501
502
503
def __init__(
    self,
    body: Expr,
    params: Arguments = Arguments(),
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.params = params
    self.body = body
    self.kind = ASTKind.LambdaExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/callables.py
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the lambda expression.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "LambdaExpr"
    value: ReprStruct = {
        "params": self.params.get_struct(simplified),
        "body": self.body.get_struct(simplified),
    }
    return self._prepare_struct(key, value, 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)
    )

ListComprehension

ListComprehension(
    element: Expr,
    generators: ASTNodes[ComprehensionClause]
    | Iterable[ComprehensionClause] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Comprehension

Methods:

Source code in packages/astx/src/astx/comprehensions.py
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def __init__(
    self,
    element: Expr,
    generators: ASTNodes[ComprehensionClause]
    | Iterable[ComprehensionClause] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the GeneratorExpr instance.
    parameters:
      element:
        type: Expr
      generators:
        type: ASTNodes[ComprehensionClause] | Iterable[ComprehensionClause]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(generators=generators, loc=loc, parent=parent)
    self.element = element

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/comprehensions.py
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"{self}"
    key += f"#{id(self)}" if simplified else ""

    generators = (
        {"generators": self.generators.get_struct(simplified)}
        if self.generators.nodes
        else {}
    )

    value: ReprStruct = {
        "element": self.element.get_struct(simplified),
        **generators,
    }
    return self._prepare_struct(key, value, 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)
    )

ListType

ListType(element_types: list[ExprType])

Bases: CollectionType

Methods:

Source code in packages/astx/src/astx/types/collections.py
34
35
36
37
38
39
40
41
def __init__(self, element_types: list[ExprType]) -> None:
    """
    title: Initialize ListType with an element type.
    parameters:
      element_types:
        type: list[ExprType]
    """
    self.element_types = element_types

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Literal

Literal(*args, **kwargs)

Bases: DataTypeOps

Methods:

Source code in packages/astx/src/astx/literals/base.py
45
46
47
def __init__(self, *args, **kwargs) -> None:  # type: ignore
    super().__init__(*args, **kwargs)
    self.ref = uuid4().hex

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralBoolean

LiteralBoolean(
    value: bool, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/boolean.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def __init__(
    self, value: bool, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralBoolean.
    parameters:
      value:
        type: bool
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = Boolean()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralComplex

LiteralComplex(
    real: float,
    imag: float,
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
def __init__(
    self,
    real: float,
    imag: float,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize a generic complex number.
    parameters:
      real:
        type: float
      imag:
        type: float
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = real, imag

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/numeric.py
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the complex literal.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"{self.__class__.__name__}: {self.value}"
    value: ReprStruct = {
        "real": self.value[0],
        "imag": self.value[1],
    }
    return self._prepare_struct(key, value, 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)
    )

LiteralComplex32

LiteralComplex32(
    real: float,
    imag: float,
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: LiteralComplex

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
def __init__(
    self,
    real: float,
    imag: float,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize LiteralComplex32.
    parameters:
      real:
        type: float
      imag:
        type: float
      loc:
        type: SourceLocation
    """
    super().__init__(real, imag, loc)
    self.type_ = Complex32()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/numeric.py
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the complex literal.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"{self.__class__.__name__}: {self.value}"
    value: ReprStruct = {
        "real": self.value[0],
        "imag": self.value[1],
    }
    return self._prepare_struct(key, value, 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)
    )

LiteralComplex64

LiteralComplex64(
    real: float,
    imag: float,
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: LiteralComplex

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
def __init__(
    self,
    real: float,
    imag: float,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize LiteralComplex64.
    parameters:
      real:
        type: float
      imag:
        type: float
      loc:
        type: SourceLocation
    """
    super().__init__(real, imag, loc)
    self.type_ = Complex64()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/numeric.py
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the complex literal.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"{self.__class__.__name__}: {self.value}"
    value: ReprStruct = {
        "real": self.value[0],
        "imag": self.value[1],
    }
    return self._prepare_struct(key, value, 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)
    )

LiteralDate

LiteralDate(
    value: str, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/temporal.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralDate.
    parameters:
      value:
        type: str
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = Date()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/temporal.py
66
67
68
69
70
71
72
73
74
75
76
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the structure of the LiteralDate object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"LiteralDate: {self.value}"
    return self._prepare_struct(key, self.value, 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)
    )

LiteralDateTime

LiteralDateTime(
    value: str, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/temporal.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralDateTime.
    parameters:
      value:
        type: str
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = DateTime()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/temporal.py
231
232
233
234
235
236
237
238
239
240
241
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the structure of the LiteralDateTime object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"LiteralDateTime: {self.value}"
    return self._prepare_struct(key, self.value, 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)
    )

LiteralDict

LiteralDict(
    elements: dict[Literal, Literal],
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/collections.py
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def __init__(
    self,
    elements: dict[Literal, Literal],
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize LiteralDict.
    parameters:
      elements:
        type: dict[Literal, Literal]
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.elements = dict(elements)
    key_types = {type(k.type_) for k in elements.keys()}
    value_types = {type(v.type_) for v in elements.values()}
    self.type_ = DictType(
        key_types.pop()() if len(key_types) == 1 else Int32(),
        value_types.pop()() if len(value_types) == 1 else Int32(),
    )
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralFloat16

LiteralFloat16(
    value: float, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
def __init__(
    self, value: float, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralFloat16.
    parameters:
      value:
        type: float
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = Float16()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralFloat32

LiteralFloat32(
    value: float, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
def __init__(
    self, value: float, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralFloat32.
    parameters:
      value:
        type: float
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = Float32()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralFloat64

LiteralFloat64(
    value: float, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
def __init__(
    self, value: float, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralFloat64.
    parameters:
      value:
        type: float
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = Float64()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralInt128

LiteralInt128(
    value: int, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralInt128.
    parameters:
      value:
        type: int
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = Int128()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralInt16

LiteralInt16(
    value: int, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralInt16.
    parameters:
      value:
        type: int
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = Int16()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralInt32

LiteralInt32(
    value: int, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralInt32.
    parameters:
      value:
        type: int
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = Int32()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralInt64

LiteralInt64(
    value: int, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralInt64.
    parameters:
      value:
        type: int
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = Int64()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralInt8

LiteralInt8(
    value: int, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralInt8.
    parameters:
      value:
        type: int
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = Int8()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralList

LiteralList(
    elements: list[Literal],
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/collections.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def __init__(
    self, elements: list[Literal], loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralList.
    parameters:
      elements:
        type: list[Literal]
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.elements = list(elements)  # Ensure correct type
    unique_types = {type(elem.type_) for elem in elements}
    self.type_ = ListType([t() for t in unique_types])
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralNone

LiteralNone(loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/base.py
 94
 95
 96
 97
 98
 99
100
101
102
103
def __init__(self, loc: SourceLocation = NO_SOURCE_LOCATION) -> None:
    """
    title: Initialize LiteralNone.
    parameters:
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = None
    self.type_ = NoneType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralSet

LiteralSet(
    elements: set[Literal],
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/collections.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def __init__(
    self, elements: set[Literal], loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralSet.
    parameters:
      elements:
        type: set[Literal]
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.elements = set(elements)
    unique_types = {type(elem.type_) for elem in elements}
    self.type_ = SetType(
        unique_types.pop()() if len(unique_types) == 1 else Int32()
    )
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralString

LiteralString(
    value: str, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/string.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralString.
    parameters:
      value:
        type: str
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = String()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/string.py
62
63
64
65
66
67
68
69
70
71
72
73
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"LiteralString: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralTime

LiteralTime(
    value: str, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/temporal.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralTime.
    parameters:
      value:
        type: str
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = Time()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/temporal.py
121
122
123
124
125
126
127
128
129
130
131
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the structure of the LiteralTime object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"LiteralTime: {self.value}"
    return self._prepare_struct(key, self.value, 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)
    )

LiteralTimestamp

LiteralTimestamp(
    value: str, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/temporal.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralTimestamp.
    parameters:
      value:
        type: str
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = Timestamp()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/temporal.py
176
177
178
179
180
181
182
183
184
185
186
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the structure of the LiteralTimestamp object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"LiteralTimestamp: {self.value}"
    return self._prepare_struct(key, self.value, 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)
    )

LiteralTuple

LiteralTuple(
    elements: tuple[Literal, ...],
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/collections.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def __init__(
    self,
    elements: tuple[Literal, ...],
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize LiteralTuple.
    parameters:
      elements:
        type: tuple[Literal, Ellipsis]
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.elements = elements
    self.type_ = TupleType([elem.type_ for elem in elements])
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralUInt128

LiteralUInt128(
    value: int, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralUInt128.
    parameters:
      value:
        type: int
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = UInt128()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralUInt16

LiteralUInt16(
    value: int, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralUInt16.
    parameters:
      value:
        type: int
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = UInt16()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralUInt32

LiteralUInt32(
    value: int, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralUInt32.
    parameters:
      value:
        type: int
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = UInt32()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralUInt64

LiteralUInt64(
    value: int, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralUInt64.
    parameters:
      value:
        type: int
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = UInt64()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralUInt8

LiteralUInt8(
    value: int, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/numeric.py
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralUInt8.
    parameters:
      value:
        type: int
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = UInt8()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralUTF8Char

LiteralUTF8Char(
    value: str, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: LiteralString

Methods:

Source code in packages/astx/src/astx/literals/string.py
142
143
144
145
146
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    super().__init__(value=value, loc=loc)
    self.type_ = UTF8Char()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/string.py
156
157
158
159
160
161
162
163
164
165
166
167
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the structure of the object in a simplified.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"LiteralUTF8Char: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

LiteralUTF8String

LiteralUTF8String(
    value: str, loc: SourceLocation = NO_SOURCE_LOCATION
)

Bases: LiteralString

Methods:

Source code in packages/astx/src/astx/literals/string.py
95
96
97
98
99
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    super().__init__(value=value, loc=loc)
    self.type_ = UTF8String()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/string.py
109
110
111
112
113
114
115
116
117
118
119
120
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the structure of the object in a simplified.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"LiteralUTF8String: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, 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)
    )

Module

Module(
    name: str = "main",
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: Block

Methods:

Attributes:

Source code in packages/astx/src/astx/packages.py
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def __init__(
    self,
    name: str = "main",
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      name:
        type: str
      loc:
        type: SourceLocation
    """
    super().__init__(name=name, loc=loc)
    self.kind = ASTKind.ModuleKind

block property

block: list[AST]

append

append(value: ASTType) -> None
Source code in packages/astx/src/astx/base.py
484
485
486
487
488
489
490
491
def append(self, value: ASTType) -> None:
    """
    title: Append a new node to the stack.
    parameters:
      value:
        type: ASTType
    """
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    block_node = []

    for node in self.nodes:
        block_node.append(node.get_struct(simplified))

    key = f"MODULE[{self.name}]"
    value = cast(ReprStruct, block_node)

    return self._prepare_struct(key, value, 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)
    )

MutabilityKind

Bases: Enum

NandOp

NandOp(
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: BoolBinaryOp

Methods:

Source code in packages/astx/src/astx/types/operators.py
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
def __init__(
    self,
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Instantiate AST class for logical NAND operation.
    parameters:
      lhs:
        type: DataType
      rhs:
        type: DataType
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(
        op_code=self.op_code,
        lhs=lhs,
        rhs=rhs,
        loc=loc,
        parent=parent,
    )

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/types/operators.py
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"BOOL_BINARY_OP[{self.__class__.__name__}]"
    value: ReprStruct = {
        "lhs": self.lhs.get_struct(simplified),
        "rhs": self.rhs.get_struct(simplified),
    }
    return self._prepare_struct(key, value, 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)
    )

NoneType

NoneType(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: AnyType

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

NorOp

NorOp(
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: BoolBinaryOp

Methods:

Source code in packages/astx/src/astx/types/operators.py
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
def __init__(
    self,
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Instantiate AST class for logical NOR operation.
    parameters:
      lhs:
        type: DataType
      rhs:
        type: DataType
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(
        op_code=self.op_code,
        lhs=lhs,
        rhs=rhs,
        loc=loc,
        parent=parent,
    )

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/types/operators.py
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"BOOL_BINARY_OP[{self.__class__.__name__}]"
    value: ReprStruct = {
        "lhs": self.lhs.get_struct(simplified),
        "rhs": self.rhs.get_struct(simplified),
    }
    return self._prepare_struct(key, value, 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)
    )

NotOp

NotOp(
    operand: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: BoolUnaryOp

Methods:

Source code in packages/astx/src/astx/types/operators.py
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
def __init__(
    self,
    operand: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Instantiate AST class for logical NOT operation.
    parameters:
      operand:
        type: DataType
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(
        op_code=self.op_code,
        operand=operand,
        loc=loc,
        parent=parent,
    )

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/types/operators.py
496
497
498
499
500
501
502
503
504
505
506
507
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"BOOL_UNARY_OP[{self.__class__.__name__}]"
    value: ReprStruct = {"operand": self.operand.get_struct(simplified)}
    return self._prepare_struct(key, value, 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)
    )

Number

Number(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: AnyType

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

OperatorType

OperatorType(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: DataType

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

OrOp

OrOp(
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: BoolBinaryOp

Methods:

Source code in packages/astx/src/astx/types/operators.py
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
def __init__(
    self,
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Instantiate AST class for logical OR operation.
    parameters:
      lhs:
        type: DataType
      rhs:
        type: DataType
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(
        op_code=self.op_code,
        lhs=lhs,
        rhs=rhs,
        loc=loc,
        parent=parent,
    )

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/types/operators.py
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"BOOL_BINARY_OP[{self.__class__.__name__}]"
    value: ReprStruct = {
        "lhs": self.lhs.get_struct(simplified),
        "rhs": self.rhs.get_struct(simplified),
    }
    return self._prepare_struct(key, value, 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)
    )

Package

Package(
    name: str = "main",
    modules: list[Module] = [],
    packages: list[Package] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: ASTNodes

Methods:

Source code in packages/astx/src/astx/packages.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def __init__(
    self,
    name: str = "main",
    modules: list[Module] = [],
    packages: list[Package] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      name:
        type: str
      modules:
        type: list[Module]
      packages:
        type: list[Package]
      loc:
        type: SourceLocation
    """
    super().__init__(loc=loc)
    self.name = name
    self.modules = copy.deepcopy(modules)
    self.packages = copy.deepcopy(packages)

append

append(value: ASTType) -> None
Source code in packages/astx/src/astx/base.py
484
485
486
487
488
489
490
491
def append(self, value: ASTType) -> None:
    """
    title: Append a new node to the stack.
    parameters:
      value:
        type: ASTType
    """
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    packages = []
    modules = []

    for package in self.packages:
        packages.append(package.get_struct(simplified))

    for module in self.modules:
        modules.append(module.get_struct(simplified))

    key = str(self)
    value = cast(
        ReprStruct,
        {
            "modules": modules,
            "packages": packages,
        },
    )

    return self._prepare_struct(key, value, 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)
    )

ParenthesizedExpr

ParenthesizedExpr(
    value: Expr,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: DataType

Methods:

Source code in packages/astx/src/astx/base.py
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
def __init__(
    self,
    value: Expr,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the ParenthesizedExpr instance.
    parameters:
      value:
        type: Expr
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.type_ = getattr(value, "type_", DataType())
    self.value = value
    self.kind = ASTKind.ParenthesizedExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
807
808
809
810
811
812
813
814
815
816
817
818
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "PARENTHESIZED-EXPR"
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, 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)
    )

Program

Program(
    name: str = "main",
    target: Target = Target("", ""),
    modules: list[Module] = [],
    packages: list[Package] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: Package

Methods:

Source code in packages/astx/src/astx/packages.py
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
def __init__(
    self,
    name: str = "main",
    target: Target = Target("", ""),
    modules: list[Module] = [],
    packages: list[Package] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      name:
        type: str
      target:
        type: Target
      modules:
        type: list[Module]
      packages:
        type: list[Package]
      loc:
        type: SourceLocation
    """
    super().__init__(
        name=name, modules=modules, packages=packages, loc=loc
    )
    self.target = copy.deepcopy(target)

append

append(value: ASTType) -> None
Source code in packages/astx/src/astx/base.py
484
485
486
487
488
489
490
491
def append(self, value: ASTType) -> None:
    """
    title: Append a new node to the stack.
    parameters:
      value:
        type: ASTType
    """
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    packages = []
    modules = []

    for package in self.packages:
        packages.append(package.get_struct(simplified))

    for module in self.modules:
        modules.append(module.get_struct(simplified))

    key = str(self)
    value = cast(
        ReprStruct,
        {
            "modules": modules,
            "packages": packages,
        },
    )

    return self._prepare_struct(key, value, 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)
    )

ScopeKind

Bases: Enum

SetComprehension

SetComprehension(
    element: Expr,
    generators: ASTNodes[ComprehensionClause]
    | Iterable[ComprehensionClause] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Comprehension

Methods:

Source code in packages/astx/src/astx/comprehensions.py
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
def __init__(
    self,
    element: Expr,
    generators: ASTNodes[ComprehensionClause]
    | Iterable[ComprehensionClause] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the SetComprehension instance.
    parameters:
      element:
        type: Expr
      generators:
        type: ASTNodes[ComprehensionClause] | Iterable[ComprehensionClause]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(generators=generators, loc=loc, parent=parent)
    self.element = element
    self.kind = ASTKind.SetComprehensionKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/comprehensions.py
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    generators = (
        {"generators": self.generators.get_struct(simplified)}
        if self.generators.nodes
        else {}
    )

    value: ReprStruct = {
        "element": self.element.get_struct(simplified),
        **generators,
    }
    key = f"{self}#{id(self)}" if simplified else f"{self}"
    return self._prepare_struct(key, value, 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)
    )

SetType

SetType(element_type: ExprType)

Bases: CollectionType

Methods:

Source code in packages/astx/src/astx/types/collections.py
65
66
67
68
69
70
71
72
def __init__(self, element_type: ExprType) -> None:
    """
    title: Initialize SetType with an element type.
    parameters:
      element_type:
        type: ExprType
    """
    self.element_type = element_type

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

SignedInteger

SignedInteger(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Integer

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

SourceLocation

SourceLocation(line: int, col: int)
Source code in packages/astx/src/astx/base.py
63
64
65
66
67
68
69
70
71
72
73
def __init__(self, line: int, col: int):
    """
    title: Initialize the source location.
    parameters:
      line:
        type: int
      col:
        type: int
    """
    self.line = line
    self.col = col

Starred

Starred(
    value: Expr,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/operators.py
404
405
406
407
408
409
410
411
412
def __init__(
    self,
    value: Expr,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.value = value
    self.kind = ASTKind.StarredKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/operators.py
422
423
424
425
426
427
428
429
430
431
432
433
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "STARRED[*]"
    content: ReprStruct = {"value": self.value.get_struct(simplified)}
    return self._prepare_struct(key, content, 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)
    )

StatementType

StatementType(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: AST

Methods:

Source code in packages/astx/src/astx/base.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct abstractmethod

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
376
377
378
379
380
381
382
383
384
385
@abstractmethod
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a structure that represents the node object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """

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)
    )

String

String(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: AnyType

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

StructDeclStmt

StructDeclStmt(
    name: str,
    attributes: Iterable[VariableDeclaration]
    | ASTNodes[VariableDeclaration] = [],
    decorators: Iterable[Expr] | ASTNodes[Expr] = [],
    methods: Iterable[FunctionDef]
    | ASTNodes[FunctionDef] = [],
    visibility: VisibilityKind = public,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/classes.py
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
def __init__(
    self,
    name: str,
    attributes: Iterable[VariableDeclaration]
    | ASTNodes[VariableDeclaration] = [],
    decorators: Iterable[Expr] | ASTNodes[Expr] = [],
    methods: Iterable[FunctionDef] | ASTNodes[FunctionDef] = [],
    visibility: VisibilityKind = VisibilityKind.public,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize StructDeclStmt instance.
    parameters:
      name:
        type: str
      attributes:
        type: Iterable[VariableDeclaration] | ASTNodes[VariableDeclaration]
      decorators:
        type: Iterable[Expr] | ASTNodes[Expr]
      methods:
        type: Iterable[FunctionDef] | ASTNodes[FunctionDef]
      visibility:
        type: VisibilityKind
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = name

    if isinstance(attributes, ASTNodes):
        self.attributes = attributes
    else:
        self.attributes = ASTNodes[VariableDeclaration]()
        for a in attributes:
            self.attributes.append(a)

    if isinstance(decorators, ASTNodes):
        self.decorators = decorators
    else:
        self.decorators = ASTNodes[Expr]()
        for decorator in decorators:
            self.decorators.append(decorator)

    if isinstance(methods, ASTNodes):
        self.methods = methods
    else:
        self.methods = ASTNodes[FunctionDef]()
        for m in methods:
            self.methods.append(m)

    self.visibility = visibility
    self.kind = ASTKind.StructDeclStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/classes.py
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    vis = dict(zip(("public", "private", "protected"), ("+", "-", "#")))
    key = f"STRUCT-DECL[{vis[self.visibility.name]}{self.name}]"

    decors_dict: ReprStruct = {}
    if self.decorators:
        decors_dict = {
            "decorators": self.decorators.get_struct(simplified)
        }

    attrs_dict: ReprStruct = {}
    if self.attributes:
        attrs_dict = {"attributes": self.attributes.get_struct(simplified)}

    methods_dict: ReprStruct = {}
    if self.methods:
        methods_dict = {"methods": self.methods.get_struct(simplified)}

    value: DictDataTypesStruct = {
        **cast(DictDataTypesStruct, decors_dict),
        **cast(DictDataTypesStruct, attrs_dict),
        **cast(DictDataTypesStruct, methods_dict),
    }

    return self._prepare_struct(key, value, 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)
    )

StructDefStmt

StructDefStmt(
    name: str,
    attributes: Iterable[VariableDeclaration]
    | ASTNodes[VariableDeclaration] = [],
    decorators: Iterable[Expr] | ASTNodes[Expr] = [],
    methods: Iterable[FunctionDef]
    | ASTNodes[FunctionDef] = [],
    visibility: VisibilityKind = public,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StructDeclStmt

Methods:

Source code in packages/astx/src/astx/classes.py
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
def __init__(
    self,
    name: str,
    attributes: Iterable[VariableDeclaration]
    | ASTNodes[VariableDeclaration] = [],
    decorators: Iterable[Expr] | ASTNodes[Expr] = [],
    methods: Iterable[FunctionDef] | ASTNodes[FunctionDef] = [],
    visibility: VisibilityKind = VisibilityKind.public,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize StructDefStmt instance.
    parameters:
      name:
        type: str
      attributes:
        type: Iterable[VariableDeclaration] | ASTNodes[VariableDeclaration]
      decorators:
        type: Iterable[Expr] | ASTNodes[Expr]
      methods:
        type: Iterable[FunctionDef] | ASTNodes[FunctionDef]
      visibility:
        type: VisibilityKind
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(
        name=name,
        attributes=attributes,
        decorators=decorators,
        methods=methods,
        visibility=visibility,
        loc=loc,
        parent=parent,
    )
    self.kind = ASTKind.StructDefStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/classes.py
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    vis = dict(zip(("public", "private", "protected"), ("+", "-", "#")))
    key = f"STRUCT-DEF[{vis[self.visibility.name]}{self.name}]"

    decors_dict: ReprStruct = {}
    if self.decorators:
        decors_dict = {
            "decorators": self.decorators.get_struct(simplified)
        }

    attrs_dict: ReprStruct = {}
    if self.attributes:
        attrs_dict = {"attributes": self.attributes.get_struct(simplified)}

    methods_dict: ReprStruct = {}
    if self.methods:
        methods_dict = {"methods": self.methods.get_struct(simplified)}

    value: DictDataTypesStruct = {
        **cast(DictDataTypesStruct, decors_dict),
        **cast(DictDataTypesStruct, attrs_dict),
        **cast(DictDataTypesStruct, methods_dict),
    }

    return self._prepare_struct(key, value, 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)
    )

SubscriptExpr

SubscriptExpr(
    value: Expr,
    index: Optional[Expr] = None,
    lower: Optional[Expr] = None,
    upper: Optional[Expr] = None,
    step: Optional[Expr] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Parameters


value: Expr The expression representing the object being indexed (e.g., an array or list). index (optional): Expr The index of the variable. lower (optional): Expr The lower bound of the slice (inclusive). upper (optional): Expr The upper bound of the slice (exclusive). step (optional): Expr The step size for the slice. loc: SourceLocation The source location of the expression. parent (optional): ASTNodes The parent AST node. parameters: value: type: Expr index: type: Optional[Expr] lower: type: Optional[Expr] upper: type: Optional[Expr] step: type: Optional[Expr] loc: type: SourceLocation parent: type: Optional[ASTNodes]

Methods:

Source code in packages/astx/src/astx/subscript.py
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def __init__(
    self,
    value: Expr,
    index: Optional[Expr] = None,
    lower: Optional[Expr] = None,
    upper: Optional[Expr] = None,
    step: Optional[Expr] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the SubscriptExpr instance.
    summary: |-

      Parameters
      ----------
      value: Expr
      The expression representing the object being indexed (e.g.,
      an array or list).
      index (optional): Expr
      The index of the variable.
      lower (optional): Expr
      The lower bound of the slice (inclusive).
      upper (optional): Expr
      The upper bound of the slice (exclusive).
      step (optional): Expr
      The step size for the slice.
      loc: SourceLocation
      The source location of the expression.
      parent (optional): ASTNodes
      The parent AST node.
    parameters:
      value:
        type: Expr
      index:
        type: Optional[Expr]
      lower:
        type: Optional[Expr]
      upper:
        type: Optional[Expr]
      step:
        type: Optional[Expr]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.value: Expr = value if value is not None else LiteralNone()
    self.index: Expr = index if index is not None else LiteralNone()
    self.lower: Expr = lower if lower is not None else LiteralNone()
    self.upper: Expr = upper if upper is not None else LiteralNone()
    self.step: Expr = step if step is not None else LiteralNone()
    self.kind = ASTKind.SubscriptExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/subscript.py
164
165
166
167
168
169
170
171
172
173
174
175
176
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "SubscriptExpr"
    value = self._get_struct_wrapper(simplified)

    return self._prepare_struct(key, value, 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)
    )

SwitchStmt

SwitchStmt(
    value: Expr,
    cases: list[CaseStmt] | ASTNodes[CaseStmt],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/flows.py
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
def __init__(
    self,
    value: Expr,
    cases: list[CaseStmt] | ASTNodes[CaseStmt],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the SwitchStmt instance.
    parameters:
      value:
        type: Expr
      cases:
        type: list[CaseStmt] | ASTNodes[CaseStmt]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.value = value

    if isinstance(cases, ASTNodes):
        self.cases = cases
    else:
        self.cases = ASTNodes[CaseStmt]()
        for case in cases:
            self.cases.append(case)

    self.kind = ASTKind.SwitchStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"SWITCH-STMT[{id(self)}]" if simplified else "SWITCH-STMT"
    case_dict = {}
    for d in range(len(self.cases)):
        case_dict[f"case_{d}"] = self.cases[d].get_struct(simplified)

    value: DictDataTypesStruct = {
        "value": self.value.get_struct(simplified),
        **cast(DictDataTypesStruct, {"cases": case_dict}),
    }
    return self._prepare_struct(key, value, 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)
    )

Target

Target(datalayout: str, triple: str)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/packages.py
42
43
44
45
46
47
48
49
50
51
52
53
def __init__(self, datalayout: str, triple: str) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      datalayout:
        type: str
      triple:
        type: str
    """
    super().__init__()
    self.datalayout = datalayout
    self.triple = triple

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
55
56
57
58
59
60
61
62
63
64
65
66
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "TARGET"
    value = f"{self.datalayout}, {self.triple}"
    return self._prepare_struct(key, value, 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)
    )

ThrowStmt

ThrowStmt(
    exception: Optional[Expr] = None,
    parent: Optional[ASTNodes] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/exceptions.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def __init__(
    self,
    exception: Optional[Expr] = None,
    parent: Optional[ASTNodes] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the instance.
    parameters:
      exception:
        type: Optional[Expr]
      parent:
        type: Optional[ASTNodes]
      loc:
        type: SourceLocation
    """
    super().__init__(loc=loc, parent=parent)
    self.exception = exception
    self.kind = ASTKind.ThrowStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/exceptions.py
74
75
76
77
78
79
80
81
82
83
84
85
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"THROW-STMT[{id(self)}]" if simplified else "THROW-STMT"
    value = self.exception.get_struct(simplified) if self.exception else ""
    return self._prepare_struct(key, value, 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)
    )

Time

Time(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Temporal

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Timestamp

Timestamp(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Temporal

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

TupleType

TupleType(element_types: list[ExprType])

Bases: CollectionType

Methods:

Source code in packages/astx/src/astx/types/collections.py
131
132
133
134
135
136
137
138
def __init__(self, element_types: list[ExprType]) -> None:
    """
    title: Initialize TupleType with multiple element types.
    parameters:
      element_types:
        type: list[ExprType]
    """
    self.element_types = element_types

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

TypeCastExpr

TypeCastExpr(
    expr: Expr,
    target_type: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/types/casting.py
42
43
44
45
46
47
48
49
50
51
52
def __init__(
    self,
    expr: Expr,
    target_type: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.expr = expr
    self.target_type = target_type
    self.kind = ASTKind.TypeCastExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/types/casting.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the TypeCast expression.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "TypeCastExpr"
    value: ReprStruct = {
        "expression": self.expr.get_struct(simplified),
        "target_type": self.target_type.get_struct(simplified),
    }

    return self._prepare_struct(key, value, 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)
    )

UInt128

UInt128(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: UnsignedInteger

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

UInt16

UInt16(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: UnsignedInteger

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

UInt32

UInt32(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: UnsignedInteger

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

UInt64

UInt64(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: UnsignedInteger

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

UInt8

UInt8(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: UnsignedInteger

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

UTF8Char

UTF8Char(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: String

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

UTF8String

UTF8String(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: String

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

UnaryOp

UnaryOp(
    op_code: str,
    operand: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: DataTypeOps

Methods:

Source code in packages/astx/src/astx/types/operators.py
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
def __init__(
    self,
    op_code: str,
    operand: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the UnaryOp instance.
    parameters:
      op_code:
        type: str
      operand:
        type: DataType
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.op_code = op_code
    self.operand = operand
    self.kind = ASTKind.UnaryOpKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/types/operators.py
290
291
292
293
294
295
296
297
298
299
300
301
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"UNARY[{self.op_code}]"
    value = self.operand.get_struct(simplified)
    return self._prepare_struct(key, value, 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)
    )

Undefined

Undefined(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/base.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
608
609
610
611
612
613
614
615
616
617
618
619
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    value = "UNDEFINED"
    key = "UNDEFINED"
    return self._prepare_struct(key, value, 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)
    )

UnsignedInteger

UnsignedInteger(
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Integer

Methods:

Source code in packages/astx/src/astx/base.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the data type.
    parameters:
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/base.py
685
686
687
688
689
690
691
692
693
694
695
696
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a simple structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, 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)
    )

Variable

Variable(
    name: str,
    type_: DataType = AnyType(),
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Identifier

Methods:

Source code in packages/astx/src/astx/data.py
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
def __init__(
    self,
    name: str,
    type_: DataType = AnyType(),
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the Variable instance.
    parameters:
      name:
        type: str
      type_:
        type: DataType
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(name=name, loc=loc, parent=parent)
    self.type_ = type_

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/data.py
265
266
267
268
269
270
271
272
273
274
275
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return a structure that represents the Identifier object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"{self.__class__.__name__.upper()}[{self.name}]"
    return self._prepare_struct(key, self.name, 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)
    )

VariableAssignment

VariableAssignment(
    name: str,
    value: Expr,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/operators.py
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
def __init__(
    self,
    name: str,
    value: Expr,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the VarExprAST instance.
    parameters:
      name:
        type: str
      value:
        type: Expr
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.loc = loc
    self.name = name
    self.value = value
    self.kind = ASTKind.VariableAssignmentKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/operators.py
216
217
218
219
220
221
222
223
224
225
226
227
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = str(self)
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, 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)
    )

VariableDeclaration

VariableDeclaration(
    name: str,
    type_: DataType,
    mutability: MutabilityKind = constant,
    visibility: VisibilityKind = public,
    scope: ScopeKind = local,
    value: Expr = UNDEFINED,
    parent: Optional[ASTNodes] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/data.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def __init__(
    self,
    name: str,
    type_: DataType,
    mutability: MutabilityKind = MutabilityKind.constant,
    visibility: VisibilityKind = VisibilityKind.public,
    scope: ScopeKind = ScopeKind.local,
    value: Expr = UNDEFINED,
    parent: Optional[ASTNodes] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the VarExprAST instance.
    parameters:
      name:
        type: str
      type_:
        type: DataType
      mutability:
        type: MutabilityKind
      visibility:
        type: VisibilityKind
      scope:
        type: ScopeKind
      value:
        type: Expr
      parent:
        type: Optional[ASTNodes]
      loc:
        type: SourceLocation
    """
    super().__init__(loc=loc, parent=parent)
    self.mutability = mutability
    self.scope = scope
    self.visibility = visibility
    self.name = name
    self.type_ = type_
    self.value = value
    self.kind = ASTKind.VarDeclKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/data.py
110
111
112
113
114
115
116
117
118
119
120
121
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = str(self)
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, 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)
    )

VisibilityKind

Bases: Enum

WalrusOp

WalrusOp(
    lhs: Variable,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
)

Bases: DataType

Methods:

Source code in packages/astx/src/astx/operators.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def __init__(
    self,
    lhs: Variable,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the WalrusOp instance.
    parameters:
      lhs:
        type: Variable
      rhs:
        type: DataType
      loc:
        type: SourceLocation
    """
    super().__init__(loc=loc)
    self.lhs = lhs
    self.rhs = rhs
    self.kind = ASTKind.WalrusOpKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/operators.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "WALRUS[:=]"
    lhs = {"lhs": self.lhs.get_struct(simplified)}
    rhs = {"rhs": self.rhs.get_struct(simplified)}

    content: ReprStruct = {**lhs, **rhs}
    return self._prepare_struct(key, content, 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)
    )

WhileExpr

WhileExpr(
    condition: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/flows.py
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
def __init__(
    self,
    condition: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the WhileExpr instance.
    parameters:
      condition:
        type: Expr
      body:
        type: Block
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.condition = condition
    self.body = body
    self.kind = ASTKind.WhileExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    while_condition = self.condition.get_struct(simplified)
    while_body = self.body.get_struct(simplified)

    key = "WHILE-EXPR"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, while_condition),
        **cast(DictDataTypesStruct, while_body),
    }

    return self._prepare_struct(key, value, 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)
    )

WhileStmt

WhileStmt(
    condition: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

Methods:

Source code in packages/astx/src/astx/flows.py
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
def __init__(
    self,
    condition: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the WhileStmt instance.
    parameters:
      condition:
        type: Expr
      body:
        type: Block
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.condition = condition
    self.body = body
    self.kind = ASTKind.WhileStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/flows.py
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    while_condition = self.condition.get_struct(simplified)
    while_body = self.body.get_struct(simplified)

    key = f"WHILE-STMT[{id(self)}]" if simplified else "WHILE-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, while_condition),
        **cast(DictDataTypesStruct, while_body),
    }

    return self._prepare_struct(key, value, 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)
    )

XnorOp

XnorOp(
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: BoolBinaryOp

Methods:

Source code in packages/astx/src/astx/types/operators.py
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
def __init__(
    self,
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Instantiate AST class for logical XNOR operation.
    parameters:
      lhs:
        type: DataType
      rhs:
        type: DataType
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(
        op_code=self.op_code,
        lhs=lhs,
        rhs=rhs,
        loc=loc,
        parent=parent,
    )

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/types/operators.py
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"BOOL_BINARY_OP[{self.__class__.__name__}]"
    value: ReprStruct = {
        "lhs": self.lhs.get_struct(simplified),
        "rhs": self.rhs.get_struct(simplified),
    }
    return self._prepare_struct(key, value, 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)
    )

XorOp

XorOp(
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: BoolBinaryOp

Methods:

Source code in packages/astx/src/astx/types/operators.py
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
def __init__(
    self,
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Instantiate AST class for logical XOR operation.
    parameters:
      lhs:
        type: DataType
      rhs:
        type: DataType
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(
        op_code=self.op_code,
        lhs=lhs,
        rhs=rhs,
        loc=loc,
        parent=parent,
    )

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/types/operators.py
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"BOOL_BINARY_OP[{self.__class__.__name__}]"
    value: ReprStruct = {
        "lhs": self.lhs.get_struct(simplified),
        "rhs": self.rhs.get_struct(simplified),
    }
    return self._prepare_struct(key, value, 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)
    )

YieldExpr

YieldExpr(
    value: Optional[Expr],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/callables.py
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
def __init__(
    self,
    value: Optional[Expr],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the YieldExpr instance.
    parameters:
      value:
        type: Optional[Expr]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.value = value
    self.kind = ASTKind.YieldExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/callables.py
704
705
706
707
708
709
710
711
712
713
714
715
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "YIELD-EXPR"
    value = {} if self.value is None else self.value.get_struct(simplified)
    return self._prepare_struct(key, value, 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)
    )

YieldFromExpr

YieldFromExpr(
    value: Expr,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/callables.py
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
def __init__(
    self,
    value: Expr,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the YieldFromExpr instance.
    parameters:
      value:
        type: Expr
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.value = value
    self.kind = ASTKind.YieldFromExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/callables.py
831
832
833
834
835
836
837
838
839
840
841
842
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "YIELDFROM-EXPR"
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, 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)
    )

YieldStmt

YieldStmt(
    value: Optional[Expr] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
)

Bases: StatementType

value: The expression to yield (optional) loc: Source location of the statement parent: Parent AST node parameters: value: type: Optional[Expr] loc: type: SourceLocation parent: type: Optional[ASTNodes]

Methods:

Source code in packages/astx/src/astx/callables.py
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
def __init__(
    self,
    value: Optional[Expr] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """
    title: Initialize the YieldStmt instance.
    summary: |-

      value: The expression to yield (optional)
      loc: Source location of the statement
      parent: Parent AST node
    parameters:
      value:
        type: Optional[Expr]
      loc:
        type: SourceLocation
      parent:
        type: Optional[ASTNodes]
    """
    super().__init__(loc=loc, parent=parent)
    self.value = value
    self.kind = ASTKind.YieldStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/callables.py
771
772
773
774
775
776
777
778
779
780
781
782
783
784
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"YIELD-STMT[{id(self)}]" if simplified else "YIELD-STMT"
    value = (
        self.value.get_struct(simplified) if self.value is not None else {}
    )
    return self._prepare_struct(key, value, 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)
    )

get_version

get_version() -> str
Source code in packages/astx/src/astx/__init__.py
210
211
212
213
214
215
216
217
218
219
def get_version() -> str:
    """
    title: Return the program version.
    returns:
      type: str
    """
    try:
        return importlib_metadata.version(__name__)
    except importlib_metadata.PackageNotFoundError:  # pragma: no cover
        return "1.19.1"  # semantic-release