Skip to content

callables

Classes:

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

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

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

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

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