Bug 150257 - [PyUNO] uno.isInstance(obj) returns 0
Summary: [PyUNO] uno.isInstance(obj) returns 0
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
7.3.5.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-04 09:36 UTC by Andreas Säger
Modified: 2023-09-21 09:49 UTC (History)
2 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 Andreas Säger 2022-08-04 09:36:14 UTC
Description:
As said in the summary, I get nothing but 0.
Expected result: True if the given object is an UNO object.

See also: https://ask.libreoffice.org/t/c-s-s-text-mailmergetype-shell-4/80148/9

Steps to Reproduce:
1. A Python script:
import uno
def test_isInstance():
    doc = XSCRIPTCONTEXT.getDocument()
    print(uno.isInstance(doc)
2. store the script under <profile>/Scripts/python/testInstance.py

3. Start the office from a terminal window, load any kind of document and run the macro.

Actual Results:
prints 0 to the terminal

Expected Results:
print True to the terminal since XSCRIPTCONTEXT.getDocument() refers to the currently active document model which is certainly an UNO object.


Reproducible: Always


User Profile Reset: No



Additional Info:
I tested this with various UNO objects that occur in my current project. Always 0.
Comment 1 Rafael Lima 2022-08-04 20:17:40 UTC
AFAIK uno.py does not have a method named isInstance so calling it would cause an error. See the contents of uno.py and this method does not exist:

https://opengrok.libreoffice.org/xref/core/pyuno/source/module/uno.py?r=c7568cfd

Maybe you're referring to the isInterface method?
Comment 2 Andreas Säger 2022-08-05 08:59:40 UTC
Yes, I mean isInterface.
Comment 3 Mike Kaganski 2022-08-05 09:47:06 UTC
Note: the code in comment 0 additionally misses the closing parenthesis. It should be

import uno
def test_isInstance():
    doc = XSCRIPTCONTEXT.getDocument()
    print(uno.isInterface(doc))

I tried it using Version: 7.4.0.2 (x64) / LibreOffice Community
Build ID: 1512ce97d7ed39dce3121f7e15651fd8895f950e
CPU threads: 12; OS: Windows 10.0 Build 19044; UI render: Skia/Raster; VCL: win
Locale: ru-RU (ru_RU); UI: en-US
Calc: CL

and indeed, it works as described.

Then I modified it like this:

import uno

def test_isInstance():
    doc = XSCRIPTCONTEXT.getDocument()
    print(uno.isInterface(uno.getClass("com.sun.star.uno.XInterface")))

and it returned 1.

I really don't know what the isInterface might be used for, but it looks like it expects some type meta-objects, not actual interface implementations.
Comment 4 Andreas Säger 2022-08-05 11:58:01 UTC
OK. Close this.
Comment 5 QA Administrators 2022-08-06 03:34:59 UTC Comment hidden (obsolete)