Skip to content

Commit a63c8a0

Browse files
committed
Intermediate: allow list of primitives
1 parent d2f768d commit a63c8a0

File tree

5 files changed

+100
-3
lines changed

5 files changed

+100
-3
lines changed

aas_core_codegen/intermediate/_translate.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -4415,17 +4415,20 @@ def _verify_only_simple_type_patterns(symbol_table: SymbolTable) -> List[Error]:
44154415
type_anno = beneath_optional(prop.type_annotation)
44164416
if isinstance(type_anno, ListTypeAnnotation):
44174417
if not (
4418-
isinstance(type_anno.items, OurTypeAnnotation)
4419-
and isinstance(
4418+
isinstance(type_anno.items, PrimitiveTypeAnnotation)
4419+
or (
4420+
isinstance(type_anno.items, OurTypeAnnotation)
4421+
and isinstance(
44204422
type_anno.items.our_type, (AbstractClass, ConcreteClass)
4423+
)
44214424
)
44224425
):
44234426
errors.append(
44244427
Error(
44254428
prop.parsed.node,
44264429
f"We currently support only a limited set of "
44274430
f"type annotation patterns. At the moment, we handle "
4428-
f"only lists of classes (both concrete or abstract), "
4431+
f"only lists of classes (both concrete or abstract) or primitive types, "
44294432
f"but the property {prop.name!r} "
44304433
f"of the class {cls.name!r} "
44314434
f"has type: {prop.type_annotation}. "
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
SymbolTable(
2+
our_types=[
3+
ConcreteClass(
4+
name='SomeContainerClass',
5+
inheritances=[],
6+
inheritance_id_set=...,
7+
ancestors=[],
8+
ancestor_id_set=...,
9+
is_implementation_specific=False,
10+
interface=None,
11+
descendant_id_set=...,
12+
descendants=[],
13+
concrete_descendant_id_set=...,
14+
concrete_descendants=[],
15+
properties=[
16+
Property(
17+
name='x',
18+
type_annotation=ListTypeAnnotation(
19+
items=PrimitiveTypeAnnotation(
20+
a_type='STR',
21+
parsed=...),
22+
parsed=...),
23+
description=None,
24+
specified_for='Reference to ConcreteClass SomeContainerClass',
25+
parsed=...)],
26+
methods=[],
27+
constructor=Constructor(
28+
name='__init__',
29+
arguments=[
30+
Argument(
31+
name='x',
32+
type_annotation=ListTypeAnnotation(
33+
items=PrimitiveTypeAnnotation(
34+
a_type='STR',
35+
parsed=...),
36+
parsed=...),
37+
default=None,
38+
parsed=...)],
39+
returns=None,
40+
description=None,
41+
contracts=Contracts(
42+
preconditions=[],
43+
snapshots=[],
44+
postconditions=[]),
45+
parsed=...,
46+
arguments_by_name=...,
47+
is_implementation_specific=False,
48+
statements=[
49+
textwrap.dedent("""\
50+
AssignArgument(
51+
name='x',
52+
argument='x',
53+
default=None)""")],
54+
inlined_statements=[
55+
textwrap.dedent("""\
56+
AssignArgument(
57+
name='x',
58+
argument='x',
59+
default=None)""")]),
60+
invariants=[],
61+
serialization=Serialization(
62+
with_model_type=False),
63+
description=None,
64+
parsed=...,
65+
properties_by_name=...,
66+
property_id_set=...,
67+
methods_by_name=...,
68+
method_id_set=...,
69+
invariant_id_set=...)],
70+
our_types_topologically_sorted=[
71+
'Reference to our type SomeContainerClass'],
72+
enumerations=[],
73+
constrained_primitives=[],
74+
classes=[
75+
'Reference to our type SomeContainerClass'],
76+
concrete_classes=[
77+
'Reference to our type SomeContainerClass'],
78+
constants=[],
79+
constants_by_name=...,
80+
verification_functions=[],
81+
verification_functions_by_name=...,
82+
meta_model=MetaModel(
83+
description=None,
84+
version='dummy',
85+
xml_namespace='https://dummy.com'))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class SomeContainerClass:
2+
x: List[str]
3+
4+
def __init__(self, x: List[str]) -> None:
5+
self.x = x
6+
7+
8+
__version__ = "dummy"
9+
__xml_namespace__ = "https://dummy.com"

0 commit comments

Comments
 (0)