symforce-org / symforce

Fast symbolic computation, code generation, and nonlinear optimization for robotics
https://symforce.org
Apache License 2.0
1.41k stars 145 forks source link

Improvements to using dataclasses in Values objects #218

Open nathan-skydio opened 2 years ago

nathan-skydio commented 2 years ago

We should treat dataclasses more like we treat Values objects stored inside other Values objects. Currently we consider a dataclass inside a values to be an element similar to an sf.V3, sf.Rot3, scalar, etc., but they are often just used as containers of other objects. This change would enable (1) accessing elements in a dataclass using dot notation and (2) better printing of Values which contain complex dataclasses.

Example of (1): We should be able to do something like values["my_dataclass.element_in_dataclass"] but currently cannot. Instead you have to do values["my_dataclass"].element_in_dataclass right now.

For (2) we just need to edit format() in values.py to print dataclasses like we print Values objects.