Skip to content

subscript

Classes:

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

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