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

Python repr fix for RecursionError caused by circular references in lanelets with regulatory elements #372

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

johannes-fischer
Copy link
Contributor

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))

@immel-f
Copy link
Contributor

immel-f commented Nov 6, 2024

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?

@johannes-fischer
Copy link
Contributor Author

I have added some python unit tests now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants