mirror-llvm-project/lldb/source/Plugins/ScriptInterpreter/Python
Med Ismail Bennani 1ac9b999f8
[lldb] Reimplement PythonCallable::GetArgInfo without executing Python code (#213378)
`b05a5d0a` added an arity-trimming step to the shared
`ScriptedPythonInterface::Dispatch`: extensions are now allowed to
define methods with trailing parameters as optional
(`num_children(self)` vs. `num_children(self, max_count)`), so before
calling into a method, `Dispatch` needs to know how many positional
arguments it actually accepts and drop any trailing ones we'd otherwise
pass.

That check calls `PythonCallable::GetArgInfo`, which ran a whole
embedded Python script through `inspect.signature` on every call, since
every scripted-extension dispatch goes through it.

For the common case `GetArgInfo()` actually needs to handle fast (plain
Python functions/methods, classes used as constructors, and callable
instances defining `__call__`, i.e. everything `Dispatch<T>()` and
`CreatePluginObject()` ever pass it), the answer is available as plain
data attributes, with no Python bytecode execution required:
`__func__`/`__self__` to unwrap bound methods, and `__code__`'s
`co_argcount`/`co_flags` for the actual positional-argument count and
varargs bit. For a class, that means `__init__` -- except a class may
customize `__new__` instead and leave `__init__` untouched, in which
case `object.__init__` becomes lenient about extra arguments.

Anything else still lacking `__code__` can fall back to the original
`inspect.signature()`-based implementation, now exposed as
`PythonCallable::GetArgInfoFromInspectSignature()` so it can be used
separately.

rdar://183776556

---------

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-08-01 16:23:21 -07:00
..
Interfaces [lldb/Interpreter] Surface Python exceptions from scripted extensions (#198153) 2026-07-31 17:51:12 -07:00
CMakeLists.txt [lldb/script] Migrate synthetic children providers onto ScriptedPythonInterface (#210845) 2026-07-30 13:39:36 -07:00
lldb-python.h [lldb][windows] Fix Python library link for LLDB_ENABLE_PYTHON_LIMITED_API (#201407) 2026-06-05 20:35:39 +01:00
PythonDataObjects.cpp [lldb] Reimplement PythonCallable::GetArgInfo without executing Python code (#213378) 2026-08-01 16:23:21 -07:00
PythonDataObjects.h [lldb] Reimplement PythonCallable::GetArgInfo without executing Python code (#213378) 2026-08-01 16:23:21 -07:00
PythonReadline.cpp
PythonReadline.h [lldb] Fix LLDB header guards (NFC) (#181312) 2026-02-12 22:21:27 -08:00
ScriptInterpreterPython.cpp [lldb] Reimplement PythonCallable::GetArgInfo without executing Python code (#213378) 2026-08-01 16:23:21 -07:00
ScriptInterpreterPython.h [lldb/script] Add scripting extension template generator (#209647) 2026-07-17 16:21:00 -07:00
ScriptInterpreterPythonImpl.h [lldb/script] Migrate synthetic children providers onto ScriptedPythonInterface (#210845) 2026-07-30 13:39:36 -07:00
SWIGPythonBridge.h [lldb/script] Migrate synthetic children providers onto ScriptedPythonInterface (#210845) 2026-07-30 13:39:36 -07:00