Details
-
Bug
-
Resolution: Done
-
P4: Low
-
None
-
5.14.2
-
None
-
-
c782714ad3e47b8a74342c95d64b69b6dd4cc270 (pyside/pyside-setup/5.15)
Description
I need to override a generated classes __getattr__ in the MonkeyPatch for attribute lookup at Python runtime:
def _my_generated_class__getattr__(self: MyGeneratedClass, name: str): # me no works print(f'MyGeneratedClass.__getattr__ called for attribute {name}') def _my_generated_class__dir__(self: MyGeneratedClass): # me works! print(f'MyGeneratedClass.__dir__ called') # in the monkey patch function MyGeneratedClass.__getattr__ = _my_generated_class__getattr__ MyGeneratedClass.__dir__ = _my_generated_class__dir__ # me works!
From what I could observe, Shiboken does write out a "__setattr__" CPython Slot-Function, which in it's most simple case just wraps "PyObject_GenericSetattr". However the "__getattr__" pendant is not being generated, which translates to "nullptr" in "class_wrapper.cpp" code.
Further it is also not possible to work around this by injecting custom code via Typesystem mechanics:
<!-- a function string to "methods" and "SignatureStrings" array - yet "slot" still points to a "nullptr", which probably is an issue here --> <add-function signature="__getattr__(PyObject*)" return="PyObject*"> <!-- THIS WILL BE SKIPPED COMPLETELY IN SHIBOKEN-GENERATOR <= 5.14.2 --> <inject-code file="my-injections.cpp" snippet="my-getattr-snippet" position="end" /> </add-function>
FYI:
Currently I am using a "custom" (personally I'd call this rather a dirty hack) Shiboken patch that makes the code-injection work. However the approach became highly incompatible between just 5.14.1 and 5.14.2.
Attachments
Issue Links
- is duplicated by
-
PYSIDE-1941 Add support for gettattro/setattro
- Closed