Skip to content

Commit b1272a9

Browse files
committed
[lldb] Handle staticmethod/classmethod descriptors in ScriptedPythonInterface
Extract `__func__` attribute from staticmethod/classmethod descriptors before treating them as callables. Python's @staticmethod and @classmethod decorators wrap methods in descriptor objects that are not directly usable as PythonCallable, when calling PyCallable_Check. The actual callable function is stored in the `__func__` attribute of these descriptors, so we need to unwrap them to properly validate and invoke decorated methods in scripted interfaces. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
1 parent a941e15 commit b1272a9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,18 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
8181
AbstractMethodCheckerCases::eNotAllocated)
8282
}
8383

84-
PythonCallable callable = callable_or_err->AsType<PythonCallable>();
84+
PythonObject method_obj = *callable_or_err;
85+
86+
// Handle staticmethod/classmethod descriptors by extracting the
87+
// `__func__` attribute.
88+
if (method_obj.HasAttribute("__func__")) {
89+
method_obj = method_obj.GetAttributeValue("__func__");
90+
if (!method_obj.IsAllocated())
91+
SET_CASE_AND_CONTINUE(method_name,
92+
AbstractMethodCheckerCases::eNotAllocated)
93+
}
94+
95+
PythonCallable callable = method_obj.AsType<PythonCallable>();
8596
if (!callable)
8697
SET_CASE_AND_CONTINUE(method_name,
8798
AbstractMethodCheckerCases::eNotCallable)

0 commit comments

Comments
 (0)