Files
odfstudio/pyuno
Stephan Bergmann 7bdd020783 Fix any2PyObject mapping of UNO exceptions
That

>             // the exception base functions want to have an "args" tuple,
>             // which contains the message

code is there ever since e80bdbafeb "initial
checkin for the pyuno-0.9.2 release" for reasons that are not clear to me, but
at least in the "TODO" scenarios from 3320b5fe2e
"Add exhaustive testing of PyUNO type mapping based on embindtest" and
1e2e9a20a4 "More exhaustive testing of PyUNO type
mapping based on embindtest" (which are hereby fixed), that
PyObject_SetAttrString would cause a Python exception, cf.

> info:pyuno.runtime:1489432:1489432:pyuno/source/module/pyuno_runtime.cxx:533: setting exception args raised Python exception <class 'AttributeError'>: AttributeError('args')

so at least catch that.  (And maybe that code is obsolete anyway it would make
even more sense to drop it altogether.)

Change-Id: Ic651d106f34e0b316cba59ae66d2402b8f86b0f8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195340
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@collabora.com>
2025-12-10 07:58:18 +01:00
..
…
…
…
…

Python UNO Bindings

UNO bindings for the Python programming language.

To have much joy debugging Python extensions you need to:

  • a) edit pythonloader.py in your install setting DEBUG=1 at the top
  • b) touch pyuno/source/module/pyuno_runtime.cxx and make debug=true in pyuno

Then you'll start to see your exceptions on the console instead of them getting lost at the UNO interface.

Python also comes with a gdb script libpython$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)m.so.1.0-gdb.py that is copied to instdir and will be auto-loaded by gdb; it provides commands like py-bt to get a Python-level backtrace, and py-print to print Python variables.

Another way to debug Python code is to use pdb: edit some initialization function to insert import pdb; pdb.set_trace() (somewhere so that it is executed early), then run soffice from a terminal and a command-line Python debugger will appear where you can set Python-level breakpoints.