[Lldb-commits] [lldb] [lldb] Handle staticmethod/classmethod descriptors in ScriptedPythonInterface (PR #170188)
Med Ismail Bennani via lldb-commits
lldb-commits at lists.llvm.org
Mon Dec 1 11:22:06 PST 2025
https://github.com/medismailben created https://github.com/llvm/llvm-project/pull/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 decorated methods in scripted interfaces.
>From 8811cbac1b81cdc42a2501a6eb2a92813d2977d2 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani <ismail at bennani.ma>
Date: Sat, 29 Nov 2025 18:03:47 -0800
Subject: [PATCH] [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 at bennani.ma>
---
.../Python/Interfaces/ScriptedPythonInterface.h | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
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)
More information about the lldb-commits
mailing list