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

Change default namespace to gen from sym #254

Closed bradley-solliday-skydio closed 1 year ago

bradley-solliday-skydio commented 1 year ago

Before this commit, the default namespace for packages generated with Codegen.generate_function was sym.

This is fine in C++, which actually has namespaces, but in python, where we instead use it as the package name, this collides with the name of the sym package.

This means that in the generated code, nothing inside the sym package can actually be accessed.

This causes problems when a generated function returns a type defined in the sym package (for example, sym.Rot3), as when the function is called, (most likely) an AttributeError is raised.

To prevent this from being the default behavior, I change the default namespace to gen.

I also change all the checked in code which previously relied on the default namespace being sym to explicitly set the namespace to sym.

bradley-solliday-skydio commented 1 year ago

Closing because we don't want to take up another top level name space, the core issue has been resolved by making sym a namespace package, and long run we'll probably move the generated code into sym.gen by default.