Hello, I’d like to use the equivalent of “isinstance” on Scenic types in Python. Is this possible? I have looked at some of the simulators and I see that I can add an attribute to each Scenic class for introspection. Is that the preferred way?
Instead, it would be nice to have a more direct approach, like the following:
In test.scenic:
class A:
name: "a"
# all derived classes have this attribue
instanceOfA: None
class B:
name: "b"
class C(A):
name: "c->a"
region = RectangularRegion((0, 0), 0, 10, 10)
new A on region
new B on region
new C on region
And then in test.py:
import scenic
# What I'd like to do:
# from test.scenic import A
scenario = scenic.scenarioFromFile("test.scenic")
scene, numIterations = scenario.generate()
for obj in scene.objects:
# What I'd like to do:
# if isinstance(obj, A):
# ...
# What I have to do instead
if hasattr(obj, "instanceOfA"):
print("Houston, we have a 'A'!")
print(obj)
Note the commented-out lines showing what I’d like to do.
The output should be:
Houston, we have a 'A'!
a
Houston, we have a 'A'!
c->a
Any help is appreciated, but in the meantime I’ll use attributes.