This MR contains some small fixes related to calling repr and str on python lanelet objects.
when calling repr of a lanelet that contains regulatory elements with a reference back to the lanelet, you currently get
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# RecursionError: maximum recursion depth exceeded while calling a Python object
This is fixed by printing only str for Lanelets in RuleParameter instead of repr, which breaks the loop
str now returns a concise information whereas repr contains the full object description in more cases.
For some reason this is not working as expected for RuleParameterMap, as can be seen by trying to run std::cout << trafficLightRegelem->getParameters();here. Hence, I had to add methods for the repr of the RuleParameterMap
Example code:
import os
import lanelet2
from lanelet2.projection import UtmProjector
map_file = os.path.join("src", "lanelet2", "lanelet2_maps", "res", "mapping_example.osm")
projector = UtmProjector(lanelet2.io.Origin(49, 8.4))
loadedMap = lanelet2.io.load(map_file, projector)
ll = loadedMap.laneletLayer[45014]
print(str(ll))
print(repr(ll))
reg_els = ll.regulatoryElements
print(str(reg_els))
print(repr(reg_els))
# Right of way
reg_el = reg_els[0]
print(str(reg_el))
print(repr(reg_el))
print(str(reg_el.parameters))
print(repr(reg_el.parameters))
Thanks for the contribution and for discovering that bug. Could you add some small test cases to the python unit tests for the repr functions you fixed?
This MR contains some small fixes related to calling
repr
andstr
on python lanelet objects.repr
of a lanelet that contains regulatory elements with a reference back to the lanelet, you currently getThis is fixed by printing only
str
forLanelet
s inRuleParameter
instead ofrepr
, which breaks the loopstr
now returns a concise information whereasrepr
contains the full object description in more cases.For some reason this is not working as expected for
RuleParameterMap
, as can be seen by trying to runstd::cout << trafficLightRegelem->getParameters();
here. Hence, I had to add methods for therepr
of theRuleParameterMap
Example code: