Skip to content

Bind std::function variables as named Python functions - #209

Open
ProfFan wants to merge 1 commit into
masterfrom
fix/callable-variable-bindings
Open

Bind std::function variables as named Python functions#209
ProfFan wants to merge 1 commit into
masterfrom
fix/callable-variable-bindings

Conversation

@ProfFan

@ProfFan ProfFan commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Global std::function variables currently become anonymous Python callables through module.attr(...) assignment. GTSAM’s DefaultKeyFormatter, for example, works at runtime but lacks function metadata, causing pybind11-stubgen to omit it.

Generate a C++ helper that selects module.def(...) for std::function values and attribute assignment for ordinary variables. C++ overload resolution handles aliases such as KeyFormatter without application-specific rules. Preserve empty functions as None and the direct C++ callback path for stored function pointers.

Updates documentation and expected generated output. MATLAB generation is unaffected.

Validation:

  • Wrap: 132 tests passed; 2 annotation tests deselected to avoid invoking a compiler.
  • Full replacement in GTSAM: all bindings regenerated; 541 stable tests passed, 6 skipped; 6 unstable tests passed.
  • Manually verified callable metadata, C++ callbacks, and stub declarations and exports. Stubgen reported no errors.
  • No new compiler-dependent tests or stubgen dependency.

Related: borglab/gtsam#2789.

@dellaert dellaert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly trusting you :-)

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