This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Emit type annotation in SWIG generated Python code.
ClosedPublic

Authored by JDevlieghere on Feb 4 2021, 6:11 PM.

Details

Summary

The Python code generated by SWIG is compatible with both Python 2 and Python 3. The -py3 option enables Python 2 incompatible features such as function annotations and abstract base classes.

Given that this only affects the generated code (and as such doesn't cause merge conflicts downstream) we're happy to enable it, i.e. this doesn't conflict with our ask in https://lists.llvm.org/pipermail/lldb-dev/2020-August/016388.html.

Diff Detail

Event Timeline

JDevlieghere created this revision.Feb 4 2021, 6:11 PM
JDevlieghere requested review of this revision.Feb 4 2021, 6:11 PM
JDevlieghere edited the summary of this revision. (Show Details)

This will be nice!

kastiglione accepted this revision.Feb 4 2021, 9:53 PM
This revision is now accepted and ready to land.Feb 4 2021, 9:53 PM
labath accepted this revision.Feb 4 2021, 11:41 PM

cool

Herald added a project: Restricted Project. · View Herald TranscriptFeb 5 2021, 8:51 AM
lanza added a comment.EditedFeb 5 2021, 12:56 PM

Thanks, Jonas! This generates bindings but they aren't entirely functional as it generates type annotations like "lldb::SBDebugger" which Python LSPs can't figure out. I ended up adding -py3 and then running some sed post-processing to convert "lldb::\(.*\)" to \1 etc: https://github.com/lanza/lldbpybind. That lldb.py works pretty well with pyright getting type info. Figuring out how to teach the build system + swig to generate proper type annotations might require a similar post processing step.