llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Med Ismail Bennani (medismailben)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/170188.diff


1 Files Affected:

- (modified) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
 (+11-1) 


``````````diff
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
index af88a69e34a13..d9cebefff5ff5 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
@@ -81,7 +81,17 @@ class ScriptedPythonInterface : virtual public 
ScriptedInterface {
                               AbstractMethodCheckerCases::eNotAllocated)
       }
 
-      PythonCallable callable = callable_or_err->AsType<PythonCallable>();
+      PythonObject method_obj = *callable_or_err;
+
+      // Handle staticmethod/classmethod descriptors by extracting __func__
+      if (method_obj.HasAttribute("__func__")) {
+        method_obj = method_obj.GetAttributeValue("__func__");
+        if (!method_obj.IsAllocated())
+          SET_CASE_AND_CONTINUE(method_name,
+                                AbstractMethodCheckerCases::eNotAllocated)
+      }
+
+      PythonCallable callable = method_obj.AsType<PythonCallable>();
       if (!callable)
         SET_CASE_AND_CONTINUE(method_name,
                               AbstractMethodCheckerCases::eNotCallable)

``````````

</details>


https://github.com/llvm/llvm-project/pull/170188
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to