Skip to content

base

Classes:

Literal

Literal(*args, **kwargs)

Bases: DataTypeOps

Methods:

Source code in packages/astx/src/astx/literals/base.py
45
46
47
def __init__(self, *args, **kwargs) -> None:  # type: ignore
    super().__init__(*args, **kwargs)
    self.ref = uuid4().hex

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    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
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)
    )

LiteralNone

LiteralNone(loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/base.py
 94
 95
 96
 97
 98
 99
100
101
102
103
def __init__(self, loc: SourceLocation = NO_SOURCE_LOCATION) -> None:
    """
    title: Initialize LiteralNone.
    parameters:
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = None
    self.type_ = NoneType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/base.py
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST representation for the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    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
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)
    )