Skip to content

numeric

ASTx Data Types module.

Classes:

LiteralComplex

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

Bases: Literal

Base class for literal complex numbers.

Methods:

  • get_struct

    Return the AST representation for the complex literal.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
263
264
265
266
267
268
269
270
271
def __init__(
    self,
    real: float,
    imag: float,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize a generic complex number."""
    super().__init__(loc)
    self.value = real, imag

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the complex literal.

Source code in src/astx/literals/numeric.py
277
278
279
280
281
282
283
284
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the complex literal."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    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

LiteralComplex32 data type class.

Methods:

  • get_struct

    Return the AST representation for the complex literal.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
292
293
294
295
296
297
298
299
300
def __init__(
    self,
    real: float,
    imag: float,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize LiteralComplex32."""
    super().__init__(real, imag, loc)
    self.type_ = Complex32()

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the complex literal.

Source code in src/astx/literals/numeric.py
277
278
279
280
281
282
283
284
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the complex literal."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    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

LiteralComplex64 data type class.

Methods:

  • get_struct

    Return the AST representation for the complex literal.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
308
309
310
311
312
313
314
315
316
def __init__(
    self,
    real: float,
    imag: float,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize LiteralComplex64."""
    super().__init__(real, imag, loc)
    self.type_ = Complex64()

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the complex literal.

Source code in src/astx/literals/numeric.py
277
278
279
280
281
282
283
284
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the complex literal."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralFloat16

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

Bases: Literal

LiteralFloat16 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
211
212
213
214
215
216
217
218
def __init__(
    self, value: float, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralFloat16."""
    super().__init__(loc)
    self.value = value
    self.type_ = Float16()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralFloat32

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

Bases: Literal

LiteralFloat32 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
228
229
230
231
232
233
234
235
def __init__(
    self, value: float, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralFloat32."""
    super().__init__(loc)
    self.value = value
    self.type_ = Float32()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralFloat64

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

Bases: Literal

LiteralFloat64 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
245
246
247
248
249
250
251
252
def __init__(
    self, value: float, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralFloat64."""
    super().__init__(loc)
    self.value = value
    self.type_ = Float64()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt128

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

Bases: Literal

LiteralInt128 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
109
110
111
112
113
114
115
116
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt128."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int128()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt16

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

Bases: Literal

LiteralInt16 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
58
59
60
61
62
63
64
65
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt16."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int16()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt32

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

Bases: Literal

LiteralInt32 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
75
76
77
78
79
80
81
82
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt32."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int32()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt64

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

Bases: Literal

LiteralInt64 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
92
93
94
95
96
97
98
99
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt64."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int64()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt8

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

Bases: Literal

LiteralInt8 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
41
42
43
44
45
46
47
48
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt8."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int8()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt128

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

Bases: Literal

LiteralUInt128 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
194
195
196
197
198
199
200
201
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt128."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt128()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt16

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

Bases: Literal

LiteralUInt16 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
143
144
145
146
147
148
149
150
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt16."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt16()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt32

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

Bases: Literal

LiteralUInt32 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
160
161
162
163
164
165
166
167
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt32."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt32()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt64

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

Bases: Literal

LiteralUInt64 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
177
178
179
180
181
182
183
184
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt64."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt64()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt8

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

Bases: Literal

LiteralUInt8 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
126
127
128
129
130
131
132
133
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt8."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt8()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    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

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )