Bug 50470 - PyUno objects not introspectable on Python 3
Summary: PyUno objects not introspectable on Python 3
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
3.5.3 release
Hardware: All All
: medium minor
Assignee: Not Assigned
URL:
Whiteboard: target:4.1.2 target:4.2.0
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-29 10:11 UTC by Thomas Kluyver
Modified: 2019-12-18 11:07 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Kluyver 2012-05-29 10:11:18 UTC
In Python 2, dir(obj) on a PyUno object correctly finds its method names. In Python 3, it fails to find any names. This means that it isn't introspected, e.g. for tab completion.

PyUno objects make their attributes visible via __members__, an older method for introspection that was removed for Python 3. The new standard is to define a __dir__() method returning the list of names. See documentation: http://docs.python.org/library/functions.html#dir . __dir__() works at least from Python 2.6.
Comment 1 David Tardon 2012-05-29 22:18:47 UTC
This should be really easy. The code that handles the __members__ function is in pyuno/source/module/pyuno.cxx at line 456; it only needs to be adapted to handle __dir__ as well.
Comment 2 Thomas Kluyver 2012-05-30 03:20:30 UTC
It's not completely trivial: obj.__members__ is a list itself, while obj.__dir__ should be a method that returns a list when called. The PyUno class doesn't yet have any regular methods defined, so it will need a bit of adaptation to declare a method to the Python C-API. The docs are here: http://docs.python.org/c-api/typeobj.html#PyTypeObject.tp_methods

But all the code needed is already there, so I think it still qualifies as an Easy Hack. If I wanted to have a go at it, can pyuno be built by itself, or would I have to build the whole of LO to test it?
Comment 3 David Tardon 2012-06-01 05:02:39 UTC
> But all the code needed is already there, so I think it still qualifies as an
> Easy Hack. If I wanted to have a go at it, can pyuno be built by itself, or
> would I have to build the whole of LO to test it?

No, you have to build the whole thing.
Comment 4 David Bolen 2013-08-12 18:01:27 UTC
I ran into this myself recently while doing some testing with LO 4.x, and have generated a patch.  Tested against current master (should apply in general to any LO 4.x).  Also built against 3.6.7 (to verify compatibility back to 2.6), though obviously it's not needed in the LO 3.x versions.

https://gerrit.libreoffice.org/5375
Comment 5 Commit Notification 2013-08-13 11:43:22 UTC
David Bolen committed a patch related to this issue.
It has been pushed to "libreoffice-4-1":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=125be9e41c2a6d40bf4646d4a8af96f5d97994d8&h=libreoffice-4-1

fdo#50470: Restore pyuno object method introspection in Python 3


It will be available in LibreOffice 4.1.2.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 6 Commit Notification 2013-08-13 11:43:43 UTC
David Bolen committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=1be8e912ba8a7d1acaf40d5a8597421c104ab39c

fdo#50470: Restore pyuno object method introspection in Python 3



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 7 Björn Michaelsen 2013-10-04 18:47:18 UTC
adding LibreOffice developer list as CC to unresolved EasyHacks for better visibility.

see e.g. http://nabble.documentfoundation.org/minutes-of-ESC-call-td4076214.html for details
Comment 8 Michael Stahl (allotropia) 2014-05-08 16:00:59 UTC
this appears to be fixed, thanks Daniel!

>>> import uno
>>> x = uno.getComponentContext()
>>> dir(x)
['/services/com.sun.star.security.AccessController/mode',
 ... 
 'ElementNames', 'ElementType', 'ImplementationId', 'ServiceManager', 'Types', 'addEventListener', 'dispose', 'getByName', 'getElementNames', 'getElementType', 'getImplementationId', 'getServiceManager', 'getTypes', 'getValueByName', 'hasByName', 'hasElements', 'insertByName', 'queryAdapter', 'queryInterface', 'removeByName', 'removeEventListener', 'replaceByName']
Comment 9 Michael Stahl (allotropia) 2014-05-08 16:03:22 UTC
(In reply to comment #8)
> this appears to be fixed, thanks Daniel!

argh sorry, thanks *David* of course