FFY00 / dbus-objects

DBus objects implementation on top of the Python type system
https://dbus-objects.readthedocs.io/en/latest/
MIT License
11 stars 4 forks source link

Some of the API in missing from the documentation #28

Closed FFY00 closed 3 years ago

FFY00 commented 3 years ago

I am not really sure why, the modules are defined in api.rst.

nojocodex commented 3 years ago

Could it be a circular import dependency?

It looks like dbus_objects.object imports dbus_objects.integration, which imports dbus_objects.object again. AFAICT object only needs integration for type checking, so you could remove the import of integration and use a forward-declaration:

diff --git a/dbus_objects/object.py b/dbus_objects/object.py
index 70750ab..bc693eb 100644
--- a/dbus_objects/object.py
+++ b/dbus_objects/object.py
@@ -10,8 +10,11 @@ import warnings
 import xml.etree.ElementTree as ET

 from typing import Any, Callable, Generator, List, Optional, Sequence, Tuple, Type
+from typing import TYPE_CHECKING
+
+if TYPE_CHECKING:
+    import dbus_objects.integration

-import dbus_objects.integration
 import dbus_objects.signature

@@ -400,7 +403,7 @@ class DBusObject():
         for signal_name, descriptor in self._dbus_signals:
             yield getattr(self, signal_name), descriptor

-    def register_server(self, server: dbus_objects.integration.DBusServerBase, path: str) -> None:
+    def register_server(self, server: 'dbus_objects.integration.DBusServerBase', path: str) -> None:
         if not self._dbus_signals:
             return
         if not server.emit_signal_callback:

See also: https://mypy.readthedocs.io/en/stable/common_issues.html#import-cycles.

FFY00 commented 3 years ago

Fixed by #32.