Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Iterate interfaces in the MRO reversed order #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sdbus/dbus_proxy_async_interface_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def _dbus_iter_interfaces_meta(
cls,
) -> Iterator[tuple[str, DbusClassMeta]]:

for base in cls.__mro__:
for base in reversed(cls.__mro__):
meta = DBUS_CLASS_TO_META.get(base)
if meta is None:
continue
Expand Down
5 changes: 3 additions & 2 deletions src/sdbus/dbus_proxy_async_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ async def properties_get_all_dict(


class DbusInterfaceCommonAsync(
DbusPeerInterfaceAsync, DbusPropertiesInterfaceAsync,
DbusIntrospectableAsync):
DbusPropertiesInterfaceAsync,
DbusIntrospectableAsync,
DbusPeerInterfaceAsync):
...
2 changes: 1 addition & 1 deletion src/sdbus/dbus_proxy_sync_interface_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _dbus_iter_interfaces_meta(
cls,
) -> Iterator[tuple[str, DbusClassMeta]]:

for base in cls.__mro__:
for base in reversed(cls.__mro__):
meta = DBUS_CLASS_TO_META.get(base)
if meta is None:
continue
Expand Down
4 changes: 2 additions & 2 deletions src/sdbus/dbus_proxy_sync_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ def properties_get_all_dict(


class DbusInterfaceCommon(
DbusPeerInterface,
DbusPropertiesInterface,
DbusIntrospectable,
DbusPropertiesInterface):
DbusPeerInterface):
...


Expand Down
16 changes: 15 additions & 1 deletion test/test_sdbus_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,9 +948,23 @@ class TwoInterface(
async def two(self) -> int:
return 2

class CombinedInterface(OneInterface, TwoInterface):
class CombinedInterface(TwoInterface, OneInterface):
...

test_combined = CombinedInterface()
test_combined_interfaces = [
iface for iface, _ in test_combined._dbus_iter_interfaces_meta()
]

# Verify the order of reported interfaces on the combined class.
self.assertEqual(test_combined_interfaces, [
"org.freedesktop.DBus.Peer",
"org.freedesktop.DBus.Introspectable",
"org.freedesktop.DBus.Properties",
"org.example.one",
"org.example.two",
])

async def test_extremely_large_string(self) -> None:
test_object, test_object_connection = initialize_object()

Expand Down
16 changes: 15 additions & 1 deletion test/test_sdbus_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,23 @@ class TwoInterface(
def two(self) -> int:
raise NotImplementedError

class CombinedInterface(OneInterface, TwoInterface):
class CombinedInterface(TwoInterface, OneInterface):
...

test_combined = CombinedInterface("org.test", "/")
test_combined_interfaces = [
iface for iface, _ in test_combined._dbus_iter_interfaces_meta()
]

# Verify the order of reported interfaces on the combined class.
self.assertEqual(test_combined_interfaces, [
"org.freedesktop.DBus.Peer",
"org.freedesktop.DBus.Introspectable",
"org.freedesktop.DBus.Properties",
"org.example.one",
"org.example.two",
])


if __name__ == '__main__':
main()