Skip to content

base

ASTx Data Types module.

Classes:

Literal

Literal(*args, **kwargs)

Bases: DataTypeOps

Literal Data type.

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/base.py
28
29
30
def __init__(self, *args, **kwargs) -> None:  # type: ignore
    super().__init__(*args, **kwargs)
    self.ref = uuid4().hex

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