Rename Python reserved keywords in wrapper interface files#2471
Rename Python reserved keywords in wrapper interface files#2471dellaert merged 1 commit intoborglab:developfrom
Conversation
|
Thanks !!!
|
|
Thanks for the feedback! For the parameter names ( For the Will push the updated changes shortly. |
|
Please limit renaming in c++ to parameter names. C++ bodies are not visible in Python anyway. |
e2a0747 to
dce40e4
Compare
|
Updated! Changes:
|
|
This is not right, renaming should happen in the Python wrapper not C++ itself |
|
@ProfFan Could you clarify what you mean? @dellaert's earlier comment asked to "please [rename] c++ names as well" so that "parameter names should be the same in Python and c++, for doc generation to work", and then followed up with "Please limit renaming in c++ to parameter names." So the current changes rename only C++ parameter names (e.g. The one exception is |
|
@ProfFan indeed, parameter names should match. |
Rename `lambda` to `_lambda` and `global` to `_global` in .i wrapper files and matching C++ header parameter names, so generated Python stubs avoid reserved keywords. The `lambda()` method on LevenbergMarquardtOptimizer is left unchanged -- the wrapper generator handles the renaming to `lambda_` in Python automatically.
dce40e4 to
655b101
Compare
|
Nope, no problems! The wrapper generator handles the mapping -- it will expose |
|
I don't think you need to change the names here, they should be handled in |
|
basically, ONLY the .i files. |
No, @ProfFan , this is incorrect. Since about a year, since we added better docs generation, argument names have to match in c++ and python. So if we change them in .i we should do this in c++ as well. |
|
Thanks Frank, I didn't realize that. However, this issue is a common task in FFI, which I don't think should be handled by renaming C++ variables. Python has a lot of reserved words, are we going to avoid all of them? |
|
This was the approach taken by @p-zach - if there’s a better way, feel free to propose and implement :-) |
|
Yes, IIRC the metadata on the wrapped functions is minimal, and without same-named parameters it is very difficult/impossible to guarantee a match between a given C++ function and the Python function that wraps it - which would mean you couldn't be sure the documentation for a C++ function is being assigned to the correct Python function. This is mostly an issue with overloaded methods. I worked at it for a while and that was the best I could find - probably there is a better way to do it, but it might take refactoring of the wrap library itself. |
Summary
The generated
.pyistub files uselambdaandglobalas parameter/method names, which are Python reserved keywords. This causes mypy to report syntax errors on the stubs.Renames in
.iwrapper files:lambda→lambda_(parameter names in SmartProjectionFactor methods, LevenbergMarquardtOptimizer method name)global→global_(parameter name in ReferenceFrameFactor)The wrapper tool already handles method name remapping (generating
self->lambda()calls under alambda_Python binding), so no C++ source changes are needed.Fixes #2322