[lldb] Handle staticmethod/classmethod descriptors in ScriptedPythonInterface (#170188)
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 the decorated methods in scripted interfaces. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
This commit is contained in:
parent
637a230ee3
commit
3ca85e74a1
2 changed files with 13 additions and 1 deletions
|
|
@ -74,7 +74,8 @@ public:
|
|||
if (!class_dict.HasKey(method_name))
|
||||
SET_CASE_AND_CONTINUE(method_name,
|
||||
AbstractMethodCheckerCases::eNotImplemented)
|
||||
auto callable_or_err = class_dict.GetItem(method_name);
|
||||
llvm::Expected<PythonObject> callable_or_err =
|
||||
class_dict.GetItem(method_name);
|
||||
if (!callable_or_err) {
|
||||
llvm::consumeError(callable_or_err.takeError());
|
||||
SET_CASE_AND_CONTINUE(method_name,
|
||||
|
|
|
|||
|
|
@ -810,6 +810,17 @@ bool PythonCallable::Check(PyObject *py_obj) {
|
|||
if (!py_obj)
|
||||
return false;
|
||||
|
||||
PythonObject python_obj(PyRefType::Borrowed, py_obj);
|
||||
|
||||
// Handle staticmethod/classmethod descriptors by extracting the
|
||||
// `__func__` attribute.
|
||||
if (python_obj.HasAttribute("__func__")) {
|
||||
PythonObject function_obj = python_obj.GetAttributeValue("__func__");
|
||||
if (!function_obj.IsAllocated())
|
||||
return false;
|
||||
return PyCallable_Check(function_obj.release());
|
||||
}
|
||||
|
||||
return PyCallable_Check(py_obj);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue