Skip to content

boolean

ASTx Data Types module.

Classes:

LiteralBoolean

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

Bases: Literal

LiteralBoolean 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/boolean.py
23
24
25
26
27
28
29
30
def __init__(
    self, value: bool, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralBoolean."""
    super().__init__(loc)
    self.value = value
    self.type_ = Boolean()
    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)
    )