Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List of Primitives #527

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions aas_core_codegen/intermediate/_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4415,17 +4415,20 @@ def _verify_only_simple_type_patterns(symbol_table: SymbolTable) -> List[Error]:
type_anno = beneath_optional(prop.type_annotation)
if isinstance(type_anno, ListTypeAnnotation):
if not (
isinstance(type_anno.items, OurTypeAnnotation)
and isinstance(
isinstance(type_anno.items, PrimitiveTypeAnnotation)
or (
isinstance(type_anno.items, OurTypeAnnotation)
and isinstance(
type_anno.items.our_type, (AbstractClass, ConcreteClass)
)
)
):
errors.append(
Error(
prop.parsed.node,
f"We currently support only a limited set of "
f"type annotation patterns. At the moment, we handle "
f"only lists of classes (both concrete or abstract), "
f"only lists of classes (both concrete or abstract) or primitive types, "
f"but the property {prop.name!r} "
f"of the class {cls.name!r} "
f"has type: {prop.type_annotation}. "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
SymbolTable(
our_types=[
ConcreteClass(
name='SomeContainerClass',
inheritances=[],
inheritance_id_set=...,
ancestors=[],
ancestor_id_set=...,
is_implementation_specific=False,
interface=None,
descendant_id_set=...,
descendants=[],
concrete_descendant_id_set=...,
concrete_descendants=[],
properties=[
Property(
name='x',
type_annotation=ListTypeAnnotation(
items=PrimitiveTypeAnnotation(
a_type='STR',
parsed=...),
parsed=...),
description=None,
specified_for='Reference to ConcreteClass SomeContainerClass',
parsed=...)],
methods=[],
constructor=Constructor(
name='__init__',
arguments=[
Argument(
name='x',
type_annotation=ListTypeAnnotation(
items=PrimitiveTypeAnnotation(
a_type='STR',
parsed=...),
parsed=...),
default=None,
parsed=...)],
returns=None,
description=None,
contracts=Contracts(
preconditions=[],
snapshots=[],
postconditions=[]),
parsed=...,
arguments_by_name=...,
is_implementation_specific=False,
statements=[
textwrap.dedent("""\
AssignArgument(
name='x',
argument='x',
default=None)""")],
inlined_statements=[
textwrap.dedent("""\
AssignArgument(
name='x',
argument='x',
default=None)""")]),
invariants=[],
serialization=Serialization(
with_model_type=False),
description=None,
parsed=...,
properties_by_name=...,
property_id_set=...,
methods_by_name=...,
method_id_set=...,
invariant_id_set=...)],
our_types_topologically_sorted=[
'Reference to our type SomeContainerClass'],
enumerations=[],
constrained_primitives=[],
classes=[
'Reference to our type SomeContainerClass'],
concrete_classes=[
'Reference to our type SomeContainerClass'],
constants=[],
constants_by_name=...,
verification_functions=[],
verification_functions_by_name=...,
meta_model=MetaModel(
description=None,
version='dummy',
xml_namespace='https://dummy.com'))
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class SomeContainerClass:
x: List[str]

def __init__(self, x: List[str]) -> None:
self.x = x


__version__ = "dummy"
__xml_namespace__ = "https://dummy.com"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The constructor argument 'x' and the property 'x' for the class 'SomeContainerClass' mismatch in type. The argument is typed as List[int] while the property is typed as List[str]. We expect the constructors and the properties to match in type.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class SomeContainerClass:
x: List[str]

def __init__(self, x: List[int]) -> None:
self.x = x


__version__ = "dummy"
__xml_namespace__ = "https://dummy.com"
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"title": "AssetAdministrationShellEnvironment",
"type": "object",
"$id": "https://dummy.com",
"definitions": {
"ListOfPrimitives": {
"type": "object",
"properties": {
"strings": {
"type": "array",
"items": {
"type": "string"
}
},
"integers": {
"type": "array",
"items": {
"type": "integer"
}
},
"booleans": {
"type": "array",
"items": {
"type": "boolean"
}
}
},
"required": [
"strings",
"integers",
"booleans"
]
},
"ModelType": {
"type": "string",
"enum": []
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Code generated to: <output dir>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"title": "AssetAdministrationShellEnvironment",
"type": "object"
}
16 changes: 16 additions & 0 deletions test_data/jsonschema/test_main/list_of_primitives/meta_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import List


class List_of_primitives():
strings: List[str]
integers: List[int]
booleans: List[bool]

def __init__(self, strings: List[str], integers: List[int], booleans: List[bool]) -> None:
self.strings = strings
self.integers = integers
self.booleans = booleans


__version__ = "dummy"
__xml_namespace__ = "https://dummy.com"
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
UnverifiedSymbolTable(
our_types=[
ConcreteClass(
name='Something',
is_implementation_specific=False,
inheritances=[],
properties=[
Property(
name='something',
type_annotation=SubscriptedTypeAnnotation(
identifier='List',
subscripts=[
AtomicTypeAnnotation(
identifier='int',
node=...)],
node=...),
description=None,
node=...)],
methods=[],
invariants=[],
serialization=None,
description=Description(
document=...,
node=...),
node=...,
properties_by_name=...,
methods_by_name=...)],
constants=[],
verification_functions=[],
meta_model=MetaModel(
description=None,
version='dummy',
xml_namespace='https://dummy.com'))
11 changes: 11 additions & 0 deletions test_data/parse/expected/list_of_primitives/int/meta_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Something:
"""
Represent something.

Indented.
"""
something: List[int]


__version__ = "dummy"
__xml_namespace__ = "https://dummy.com"
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
UnverifiedSymbolTable(
our_types=[
ConcreteClass(
name='Something',
is_implementation_specific=False,
inheritances=[],
properties=[
Property(
name='something',
type_annotation=SubscriptedTypeAnnotation(
identifier='List',
subscripts=[
AtomicTypeAnnotation(
identifier='str',
node=...)],
node=...),
description=None,
node=...)],
methods=[],
invariants=[],
serialization=None,
description=Description(
document=...,
node=...),
node=...,
properties_by_name=...,
methods_by_name=...)],
constants=[],
verification_functions=[],
meta_model=MetaModel(
description=None,
version='dummy',
xml_namespace='https://dummy.com'))
11 changes: 11 additions & 0 deletions test_data/parse/expected/list_of_primitives/string/meta_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Something:
"""
Represent something.

Indented.
"""
something: List[str]


__version__ = "dummy"
__xml_namespace__ = "https://dummy.com"