-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[lldb] Handle staticmethod/classmethod descriptors in ScriptedPythonInterface #170188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb] Handle staticmethod/classmethod descriptors in ScriptedPythonInterface #170188
Conversation
|
@llvm/pr-subscribers-lldb Author: Med Ismail Bennani (medismailben) ChangesExtract The actual callable function is stored in the Full diff: https://github.com/llvm/llvm-project/pull/170188.diff 1 Files Affected:
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)
|
8811cba to
b1272a9
Compare
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
Outdated
Show resolved
Hide resolved
|
|
||
| // Handle staticmethod/classmethod descriptors by extracting the | ||
| // `__func__` attribute. | ||
| if (method_obj.HasAttribute("__func__")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we may need this logic elsewhere? If so, would it make sense to put this into a static method in PythonCallable? Something like Expected<PythonCallable> PythonCallable::GetCallable(PythonObject* object)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this as part of static bool PythonCallable::Check which I think makes most sense. T::Check gets invoked when calling T PythonObject::AsType<T>.
…nterface 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>
b1272a9 to
9fa429e
Compare
JDevlieghere
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
Extract
__func__attribute from staticmethod/classmethod descriptors before treating them as callables. Python's@staticmethodand@classmethoddecorators 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.