Skip to content

Commit e7bd8dc

Browse files
committed
Fix interface compositioning not working because of common interfaces
The issue is that any interface has the interfaces like `org.freedesktop.DBus.Introspectable` or `org.freedesktop.DBus.Properties`. The interface names and member names of those built-in interfaces should not be checked for collisions. Thank you @AndersBlomdell for testing NetworkManager binds against development version.
1 parent 8b11d3f commit e7bd8dc

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

src/sdbus/dbus_proxy_async_interface_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ def __new__(cls, name: str,
9797
f"async interface: {attr_name!r}"
9898
)
9999

100+
if not serving_enabled:
101+
continue
102+
100103
if isinstance(attr, DbusMethodAsync):
101104
dbus_class_meta.dbus_member_to_python_attr[
102105
attr.method_name] = attr_name

src/sdbus/dbus_proxy_sync_interface_base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __new__(cls, name: str,
4646
) -> DbusInterfaceMetaSync:
4747

4848
dbus_class_meta = DbusClassMeta()
49-
if interface_name is not None:
49+
if interface_name is not None and serving_enabled:
5050
dbus_class_meta.dbus_interfaces_names.add(interface_name)
5151

5252
for attr_name, attr in namespace.items():
@@ -58,6 +58,9 @@ def __new__(cls, name: str,
5858
f"Can't mix async methods in sync interface: {attr_name!r}"
5959
)
6060

61+
if not serving_enabled:
62+
continue
63+
6164
if isinstance(attr, DbusMethodSync):
6265
dbus_class_meta.dbus_member_to_python_attr[
6366
attr.method_name] = attr_name

test/test_sdbus_async.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,12 @@ def test_property_setter(self, var: str) -> None:
350350

351351
with self.subTest('Test dbus to python mapping'):
352352
self.assertIn(
353-
"PropertiesChanged",
353+
"TestInt",
354354
test_object._dbus_meta.dbus_member_to_python_attr,
355355
)
356356

357357
self.assertIn(
358-
"PropertiesChanged",
358+
"TestInt",
359359
test_subclass._dbus_meta.dbus_member_to_python_attr,
360360
)
361361

@@ -887,3 +887,23 @@ async def catch_properties_changed() -> int:
887887
await wait_for(catch_changed_task, timeout=1),
888888
10,
889889
)
890+
891+
async def test_interface_composition(self) -> None:
892+
class OneInterface(
893+
DbusInterfaceCommonAsync,
894+
interface_name="org.example.one",
895+
):
896+
@dbus_method_async(result_signature="x")
897+
async def one(self) -> int:
898+
raise NotImplementedError
899+
900+
class TwoInterface(
901+
DbusInterfaceCommonAsync,
902+
interface_name="org.example.two",
903+
):
904+
@dbus_method_async(result_signature="t")
905+
async def two(self) -> int:
906+
return 2
907+
908+
class CombinedInterface(OneInterface, TwoInterface):
909+
...

test/test_sdbus_block.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from sdbus.unittest import IsolatedDbusTestCase
2727
from sdbus_block.dbus_daemon import FreedesktopDbus
2828

29+
from sdbus import DbusInterfaceCommon, dbus_method
30+
2931

3032
class TestSync(IsolatedDbusTestCase):
3133

@@ -70,6 +72,26 @@ def test_docstring(self) -> None:
7072
with self.subTest('Property doc (through class dict)'):
7173
self.assertTrue(getdoc(s.__class__.__dict__['features']))
7274

75+
def test_interface_composition(self) -> None:
76+
class OneInterface(
77+
DbusInterfaceCommon,
78+
interface_name="org.example.one",
79+
):
80+
@dbus_method(result_signature="x")
81+
def one(self) -> int:
82+
raise NotImplementedError
83+
84+
class TwoInterface(
85+
DbusInterfaceCommon,
86+
interface_name="org.example.two",
87+
):
88+
@dbus_method(result_signature="t")
89+
def two(self) -> int:
90+
raise NotImplementedError
91+
92+
class CombinedInterface(OneInterface, TwoInterface):
93+
...
94+
7395

7496
if __name__ == '__main__':
7597
main()

0 commit comments

Comments
 (0)