Skip to content

types

Provide semantic-facing type nodes that extend the upstream ASTx type model without coupling them to template metadata helpers.

Classes:

GeneratorType

GeneratorType(yield_type: DataType)

Bases: AnyType

Represent one stateful generator value that yields values of one statically known element type when iterated. attributes: yield_type: type: astx.DataType

Methods:

Source code in packages/irx/src/irx/astx/types.py
153
154
155
156
157
158
159
160
161
def __init__(self, yield_type: astx.DataType) -> None:
    """
    title: Initialize one generator type.
    parameters:
      yield_type:
        type: astx.DataType
    """
    super().__init__()
    self.yield_type = yield_type

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/types.py
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Build one repr structure for a generator type.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "GENERATOR-TYPE",
        cast(
            astx.base.ReprStruct,
            {"yield_type": self.yield_type.get_struct(simplified)},
        ),
        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)
    )

TemplateTypeVar

TemplateTypeVar(name: str, *, bound: DataType)

Bases: AnyType

Represent one unresolved template type parameter inside function signatures or local declared types before specialization. attributes: name: type: str bound: type: astx.DataType

Methods:

Source code in packages/irx/src/irx/astx/types.py
 98
 99
100
101
102
103
104
105
106
107
108
109
def __init__(self, name: str, *, bound: astx.DataType) -> None:
    """
    title: Initialize one template type variable.
    parameters:
      name:
        type: str
      bound:
        type: astx.DataType
    """
    super().__init__()
    self.name = name
    self.bound = bound

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/types.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Build one repr structure for a template type variable.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"TEMPLATE_TYPE_VAR[{self.name}]"
    value = cast(
        astx.base.DataTypesStruct,
        {
            "name": self.name,
            "bound": self.bound.get_struct(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)
    )

UnionType

UnionType(
    members: Iterable[DataType],
    *,
    alias_name: str | None = None,
)

Bases: AnyType

Represent one union of concrete type references that semantic analysis may enumerate as a finite type domain. attributes: members: type: tuple[astx.DataType, Ellipsis] alias_name: type: str | None

Methods:

Source code in packages/irx/src/irx/astx/types.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def __init__(
    self,
    members: Iterable[astx.DataType],
    *,
    alias_name: str | None = None,
) -> None:
    """
    title: Initialize one finite union type.
    parameters:
      members:
        type: Iterable[astx.DataType]
      alias_name:
        type: str | None
    """
    super().__init__()
    self.members = tuple(members)
    self.alias_name = alias_name

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/types.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Build one repr structure for a finite union type.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"UNION[{self.alias_name or id(self)}]"
    value = cast(
        astx.base.DataTypesStruct,
        [member.get_struct(simplified) for member in self.members],
    )
    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)
    )