Skip to content

Commit 511cddb

Browse files
committed
sdk/basyx/aas/examples/tutorial_navigate_aas.py: Fix mypy errors
1 parent 8800906 commit 511cddb

1 file changed

Lines changed: 51 additions & 17 deletions

File tree

sdk/basyx/aas/examples/tutorial_navigate_aas.py

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
from basyx.aas import model
9+
from typing import cast
910

1011
# In this tutorial, you will learn how to create a Submodel with different kinds of SubmodelElements and how to navigate
1112
# through them using IdShorts and IdShortPaths.
@@ -108,33 +109,66 @@
108109
#########################################################################
109110

110111
# Step 2.1: Access a single Property via its IdShort
111-
my_property = submodel.get_referable("MyProperty")
112+
my_property = cast(model.Property, submodel.get_referable("MyProperty"))
112113
print(f"my_property: id_short = {my_property.id_short}, value = {my_property.value}\n")
113114

114115
# Step 2.2.1: Access a Property within a Property Collection step by step via its IdShort
115-
my_property_collection = submodel.get_referable("MyPropertyCollection")
116-
my_property_collection_0 = my_property_collection.get_referable("MyProperty0")
117-
print(f"my_property_collection_0: id_short = {my_property_collection_0}, value = {my_property_collection_0.value}")
116+
my_property_collection = cast(model.SubmodelElementCollection, submodel.get_referable("MyPropertyCollection"))
117+
my_property_collection_property_0 = cast(model.Property, my_property_collection.get_referable("MyProperty0"))
118+
print(
119+
f"my_property_collection_property_0: "
120+
f"id_short = {my_property_collection_property_0}, "
121+
f"value = {my_property_collection_property_0.value}"
122+
)
118123

119124
# Step 2.2.2: Access a Property within a Property Collection via its IdShortPath
120-
my_property_collection_1 = submodel.get_referable(["MyPropertyCollection", "MyProperty1"])
121-
print(f"my_property_collection_1: id_short = {my_property_collection_1}, value = {my_property_collection_1.value}\n")
125+
my_property_collection_property_1 = cast(
126+
model.Property,
127+
submodel.get_referable(["MyPropertyCollection", "MyProperty1"])
128+
)
129+
print(
130+
f"my_property_collection_property_1: "
131+
f"id_short = {my_property_collection_property_1}, "
132+
f"value = {my_property_collection_property_1.value}\n"
133+
)
122134

123135
# Step 2.3.1: Access a Property within a Property List step by step via its index
124-
my_property_list = submodel.get_referable("MyPropertyList")
125-
my_property_list_0 = my_property_list.get_referable("0")
126-
print(f"my_property_list_0: id_short = {my_property_list_0}, value = {my_property_list_0.value}")
136+
my_property_list = cast(model.SubmodelElementList, submodel.get_referable("MyPropertyList"))
137+
my_property_list_property_0 = cast(model.Property, my_property_list.get_referable("0"))
138+
print(
139+
f"my_property_list_property_0: "
140+
f"id_short = {my_property_list_property_0}, "
141+
f"value = {my_property_list_property_0.value}"
142+
)
127143

128144
# Step 2.3.2: Access a Property within a Property List via its IdShortPath
129-
my_property_list_1 = submodel.get_referable(["MyPropertyList", "1"])
130-
print(f"my_property_list_1: id_short = {my_property_list_1}, value = {my_property_list_1.value}\n")
145+
my_property_list_property_1 = cast(model.Property, submodel.get_referable(["MyPropertyList", "1"]))
146+
print(
147+
f"my_property_list_property_1: "
148+
f"id_short = {my_property_list_property_1}, "
149+
f"value = {my_property_list_property_1.value}\n"
150+
)
131151

132152
# Step 2.4.1: Access a Property within a Collection List step by step via its index and IdShort
133-
my_collection_list = submodel.get_referable("MyCollectionList")
134-
my_collection_list_0 = my_collection_list.get_referable("0")
135-
my_collection_list_0_0 = my_collection_list_0.get_referable("MyProperty")
136-
print(f"my_collection_list_0_0: id_short = {my_collection_list_0_0}, value = {my_collection_list_0_0.value}")
153+
my_collection_list = cast(model.SubmodelElementList, submodel.get_referable("MyCollectionList"))
154+
my_collection_list_collection_0 = cast(model.SubmodelElementCollection, my_collection_list.get_referable("0"))
155+
my_collection_list_collection_0_property_0 = cast(
156+
model.Property,
157+
my_collection_list_collection_0.get_referable("MyProperty")
158+
)
159+
print(
160+
f"my_collection_list_collection_0_property_0: "
161+
f"id_short = {my_collection_list_collection_0_property_0}, "
162+
f"value = {my_collection_list_collection_0_property_0.value}"
163+
)
137164

138165
# Step 2.4.2: Access a Property within a Collection List via its IdShortPath
139-
my_collection_list_2_0 = submodel.get_referable(["MyCollectionList", "2", "MyProperty"])
140-
print(f"my_collection_list_2_0: id_short = {my_collection_list_2_0}, value = {my_collection_list_2_0.value}")
166+
my_collection_list_collection_2_property_0 = cast(
167+
model.Property,
168+
submodel.get_referable(["MyCollectionList", "2", "MyProperty"])
169+
)
170+
print(
171+
f"my_collection_list_collection_2_property_0: "
172+
f"id_short = {my_collection_list_collection_2_property_0}, "
173+
f"value = {my_collection_list_collection_2_property_0.value}"
174+
)

0 commit comments

Comments
 (0)