Files
Neil Roberts d2429a3c46 pyuno: Reuse wrapped object when converting Python obj through UNO and back
When any2PyObject is given an interface which is actually an adapter for
a Python object, it now returns the original Python object instead of a
new wrapper for the object. This means that calling methods on the
returned object will be faster because they won’t involve UNO bridging.
It also means that Python implementations of UNO interfaces can detect
when they are given Python objects as a parameter and take advantage of
any internal private data attached to the object.

Change-Id: Ie13d0612f48e70973bd523e68710ec33a7875a16
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207507
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-07-15 09:09:22 +02:00

33 lines
1.0 KiB
Python

# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
import unittest
import unohelper
import org.libreoffice.unotest
from org.libreoffice.embindtest import thePassthrough
class MyUnoObject(unohelper.Base):
pass
class PassthroughTest(unittest.TestCase):
def test_passthrough(self):
ctx = org.libreoffice.unotest.pyuno.getComponentContext()
# Instantiate a Python object that exposes an UNO interface
my_uno_object = MyUnoObject()
# If we pass it through an UNO interface and back we should get exactly the same python
# object back.
returned_uno_object = thePassthrough.get(ctx).passthrough(my_uno_object)
self.assertEqual(id(my_uno_object), id(returned_uno_object))
# vim: set shiftwidth=4 softtabstop=4 expandtab: