diff --git a/docs/source/high-level-service/index.rst b/docs/source/high-level-service/index.rst index 99f7a972..89c5b4e7 100644 --- a/docs/source/high-level-service/index.rst +++ b/docs/source/high-level-service/index.rst @@ -38,7 +38,7 @@ method will be provided by the calling client and will conform to the parameter type annotations. The value returned by the class method will be returned to the client and must conform to the return type annotation specified by the user. If the return annotation specifies more than one -type, the values must be returned in a ``list``. When +type, the values must be returned in a ``tuple``. When :class:`aio.MessageBus` is used, methods can be coroutines. A class method decorated with ``@dbus_property()`` will be exposed as a @@ -58,7 +58,7 @@ DBus signal. The value returned by the class method will be emitted as a signal and broadcast to clients who are listening to the signal. The returned value must conform to the return annotation of the class method as a DBus signature string. If the signal has more than one argument, -they must be returned within a ``list``. +they must be returned within a ``tuple``. A class method decorated with ``@dbus_method()`` or ``@dbus_property()`` may throw a :class:`DBusError ` to return a @@ -103,7 +103,7 @@ constructor to use unix file descriptors. async def Bazify(self, bar: '(iiu)') -> 'vv': print(f'called Bazify with bar={bar}') - return [Variant('s', 'example'), Variant('s', 'bazify')] + return Variant('s', 'example'), Variant('s', 'bazify') @dbus_method() def Mogrify(self, bar: '(iiav)'): diff --git a/examples/example-service.py b/examples/example-service.py index 43943d06..15d940a8 100755 --- a/examples/example-service.py +++ b/examples/example-service.py @@ -22,7 +22,7 @@ def Echo(self, what: "s") -> "s": @dbus_method() def EchoMultiple(self, what1: "s", what2: "s") -> "ss": - return [what1, what2] + return what1, what2 @dbus_method() def GetVariantDict(self) -> "a{sv}": # noqa: F722 @@ -46,7 +46,7 @@ def signal_simple(self) -> "s": @dbus_signal() def signal_multiple(self) -> "ss": - return ["hello", "world"] + return "hello", "world" async def main(): diff --git a/src/dbus_fast/_private/marshaller.pxd b/src/dbus_fast/_private/marshaller.pxd index ee1e5120..810e023b 100644 --- a/src/dbus_fast/_private/marshaller.pxd +++ b/src/dbus_fast/_private/marshaller.pxd @@ -17,7 +17,7 @@ cdef class Marshaller: cdef SignatureTree signature_tree cdef bytearray _buf - cdef cython.list body + cdef object body cdef _buffer(self) diff --git a/src/dbus_fast/_private/marshaller.py b/src/dbus_fast/_private/marshaller.py index b1586dff..ef263d51 100644 --- a/src/dbus_fast/_private/marshaller.py +++ b/src/dbus_fast/_private/marshaller.py @@ -25,7 +25,7 @@ class Marshaller: __slots__ = ("_buf", "body", "signature_tree") - def __init__(self, signature: str, body: list[Any]) -> None: + def __init__(self, signature: str, body: list[Any] | tuple[Any, ...]) -> None: """Marshaller constructor.""" self.signature_tree = get_signature_tree(signature) self._buf = bytearray() diff --git a/src/dbus_fast/_private/util.py b/src/dbus_fast/_private/util.py index 096a9bc6..207fba90 100644 --- a/src/dbus_fast/_private/util.py +++ b/src/dbus_fast/_private/util.py @@ -9,7 +9,7 @@ def signature_contains_type( - signature: str | SignatureTree, body: list[Any], token: str + signature: str | SignatureTree, body: list[Any] | tuple[Any, ...], token: str ) -> bool: """For a given signature and body, check to see if it contains any members with the given token""" @@ -50,8 +50,8 @@ def signature_contains_type( def replace_fds_with_idx( - signature: str | SignatureTree, body: list[Any] -) -> tuple[list[Any], list[int]]: + signature: str | SignatureTree, body: list[Any] | tuple[Any, ...] +) -> tuple[list[Any] | tuple[Any, ...], list[int]]: """Take the high level body format and convert it into the low level body format. Type 'h' refers directly to the fd in the body. Replace that with an index and return the corresponding list of unix fds that can be set on @@ -77,7 +77,9 @@ def _replace(fd: Any) -> int: def replace_idx_with_fds( - signature: str | SignatureTree, body: list[Any], unix_fds: list[Any] + signature: str | SignatureTree, + body: list[Any] | tuple[Any, ...], + unix_fds: list[Any], ) -> list[Any]: """Take the low level body format and return the high level body format. Type 'h' refers to an index in the unix_fds array. Replace those with the @@ -130,7 +132,7 @@ def raise_value_error() -> None: def _replace_fds( - body_obj: dict[Any, Any] | list[Any], + body_obj: dict[Any, Any] | list[Any] | tuple[Any, ...], children: list[SignatureType], replace_fn: Callable[[Any], Any], ) -> None: diff --git a/src/dbus_fast/aio/proxy_object.py b/src/dbus_fast/aio/proxy_object.py index 10ef6f4d..1ebde1d6 100644 --- a/src/dbus_fast/aio/proxy_object.py +++ b/src/dbus_fast/aio/proxy_object.py @@ -45,7 +45,7 @@ class ProxyInterface(BaseProxyInterface): DBus methods are exposed as coroutines that take arguments that correpond to the *in args* of the interface method definition and return a ``result`` that corresponds to the *out arg*. If the method has more than one out arg, - they are returned within a :class:`list`. + they are returned within a :class:`tuple`. To *listen to a signal* use this form: diff --git a/src/dbus_fast/glib/proxy_object.py b/src/dbus_fast/glib/proxy_object.py index 36659eac..532ae88d 100644 --- a/src/dbus_fast/glib/proxy_object.py +++ b/src/dbus_fast/glib/proxy_object.py @@ -56,8 +56,8 @@ def callback(error: Exception, result: list(Any)): To *synchronously* call a method, use the ``call_[METHOD]_sync()`` form. The ``result`` corresponds to the *out arg* of the introspection method - definition. If the method has more than one otu arg, they are returned - within a :class:`list`. + definition. If the method has more than one out arg, they are returned + within a :class:`tuple`. To *listen to a signal* use this form: diff --git a/src/dbus_fast/message.py b/src/dbus_fast/message.py index 0e946c90..abe0a78b 100644 --- a/src/dbus_fast/message.py +++ b/src/dbus_fast/message.py @@ -82,7 +82,7 @@ class Message: :ivar signature_tree: The signature parsed as a signature tree. :vartype signature_tree: :class:`SignatureTree` :ivar body: The body of this message. Must match the signature. - :vartype body: list(Any) + :vartype body: list(Any) | tuple(Any, ...) :ivar serial: The serial of the message. Will be automatically set during message sending if not present. Use the ``new_serial()`` method of the bus to generate a serial. :vartype serial: int @@ -125,7 +125,7 @@ def __init__( sender: str | None = None, unix_fds: list[int] = [], signature: SignatureTree | str | None = None, - body: list[Any] = [], + body: list[Any] | tuple[Any, ...] = [], serial: int | None = None, validate: bool = True, ) -> None: @@ -161,7 +161,7 @@ def _fast_init( sender: _str, unix_fds: _list[int], signature_tree: SignatureTree, - body: _list[Any], + body: _list[Any] | tuple[Any, ...], serial: _int, validate: _bool, ) -> None: @@ -247,7 +247,7 @@ def new_error( def new_method_return( msg: "Message", signature: str = "", - body: list[Any] = [], + body: list[Any] | tuple[Any, ...] = [], unix_fds: list[int] = [], ) -> "Message": """A convenience constructor to create a method return to the given method call message. @@ -257,7 +257,7 @@ def new_method_return( :param signature: The signature for the message body. :type signature: str :param body: The body of this message. Must match the signature. - :type body: list(Any) + :type body: list(Any) | tuple(Any, ...) :param unix_fds: List integer file descriptors to send with this message. :type unix_fds: list(int) @@ -282,7 +282,7 @@ def new_signal( interface: str, member: str, signature: str = "", - body: list[Any] | None = None, + body: list[Any] | tuple[Any, ...] | None = None, unix_fds: list[int] | None = None, ) -> "Message": """A convenience constructor to create a new signal message. @@ -296,7 +296,7 @@ def new_signal( :param signature: The signature of the signal body. :type signature: str :param body: The body of this signal message. - :type body: list(Any) + :type body: list(Any) | tuple[Any, ...] :param unix_fds: List integer file descriptors to send with this message. :type unix_fds: list(int) diff --git a/src/dbus_fast/message_bus.py b/src/dbus_fast/message_bus.py index 85fe5780..c65f3918 100644 --- a/src/dbus_fast/message_bus.py +++ b/src/dbus_fast/message_bus.py @@ -626,7 +626,7 @@ def _interface_signal_notify( interface_name: str, member: str, signature: str, - body: list[Any], + body: list[Any] | tuple[Any, ...], unix_fds: list[int] = [], ) -> None: path: str | None = None diff --git a/src/dbus_fast/service.py b/src/dbus_fast/service.py index e59b788a..acdd7e4f 100644 --- a/src/dbus_fast/service.py +++ b/src/dbus_fast/service.py @@ -97,7 +97,7 @@ def dbus_method( client and will conform to the dbus-fast type system. The parameters returned will be returned to the calling client and must conform to the dbus-fast type system. If multiple parameters are returned, they must be - contained within a :class:`list`. + contained within a :class:`tuple`. The decorated method may raise a :class:`DBusError ` to return an error to the client. @@ -117,7 +117,7 @@ def echo(self, val: 's') -> 's': @dbus_method() def echo_two(self, val1: 's', val2: 'u') -> 'su': - return [val1, val2] + return val1, val2 .. versionadded:: v2.46.0 In older versions, this was named ``@method``. The old name still exists. @@ -188,7 +188,7 @@ def dbus_signal( annotation with a signature string of a single complete DBus type and the return value of the class method must conform to the dbus-fast type system. If the signal has multiple out arguments, they must be returned within a - ``list``. + ``tuple``. :param name: The member name that will be used for this signal. Defaults to the name of the class method. @@ -206,7 +206,7 @@ def string_signal(self, val) -> 's': @dbus_signal() def two_strings_signal(self, val1, val2) -> 'ss': - return [val1, val2] + return val1, val2 .. versionadded:: v2.46.0 In older versions, this was named ``@signal``. The old name still exists. @@ -361,7 +361,7 @@ def _real_fn_result_to_body( result: Any | None, signature_tree: SignatureTree, replace_fds: bool, -) -> tuple[list[Any], list[int]]: +) -> tuple[list[Any] | tuple[Any, ...], list[int]]: out_len = len(signature_tree.types) if result is None: final_result = [] @@ -573,7 +573,7 @@ def _msg_body_to_args(msg: Message) -> list[Any]: return ServiceInterface._c_msg_body_to_args(msg) @staticmethod - def _c_msg_body_to_args(msg: Message) -> list[Any]: + def _c_msg_body_to_args(msg: Message) -> list[Any] | tuple[Any, ...]: # https://github.com/cython/cython/issues/3327 if not signature_contains_type(msg.signature_tree, msg.body, "h"): return msg.body @@ -590,7 +590,7 @@ def _fn_result_to_body( result: Any | None, signature_tree: SignatureTree, replace_fds: bool = True, - ) -> tuple[list[Any], list[int]]: + ) -> tuple[list[Any] | tuple[Any, ...], list[int]]: return _real_fn_result_to_body(result, signature_tree, replace_fds) @staticmethod @@ -598,7 +598,7 @@ def _c_fn_result_to_body( result: Any | None, signature_tree: SignatureTree, replace_fds: bool, - ) -> tuple[list[Any], list[int]]: + ) -> tuple[list[Any] | tuple[Any, ...], list[int]]: """The high level interfaces may return single values which may be wrapped in a list to be a message body. Also they may return fds directly for type 'h' which need to be put into an external list.""" diff --git a/src/dbus_fast/signature.py b/src/dbus_fast/signature.py index 6b88a0f6..4eae2bc8 100644 --- a/src/dbus_fast/signature.py +++ b/src/dbus_fast/signature.py @@ -380,12 +380,11 @@ def __eq__(self, other: object) -> bool: return self.signature == other.signature return super().__eq__(other) - def verify(self, body: list[Any]) -> bool: + def verify(self, body: list[Any] | tuple[Any, ...]) -> bool: """Verifies that the give body matches this signature tree :param body: the body to verify for this tree - :type body: list(Any) - + :type body: list(Any) | tuple(Any, ...) :returns: True if the signature matches the body or an exception if not. :raises: diff --git a/tests/client/test_methods.py b/tests/client/test_methods.py index b0afb422..a322183f 100644 --- a/tests/client/test_methods.py +++ b/tests/client/test_methods.py @@ -38,7 +38,7 @@ def ConcatStrings(self, what1: "s", what2: "s") -> "s": @dbus_method() def EchoThree(self, what1: "s", what2: "s", what3: "s") -> "sss": - return [what1, what2, what3] + return what1, what2, what3 @dbus_method() def GetComplex(self) -> "a{sv}": # noqa: F722 diff --git a/tests/client/test_signals.py b/tests/client/test_signals.py index bfe2ee7e..3482471b 100644 --- a/tests/client/test_signals.py +++ b/tests/client/test_signals.py @@ -20,7 +20,7 @@ def SomeSignal(self) -> "s": @dbus_signal() def SignalMultiple(self) -> "ss": - return ["hello", "world"] + return "hello", "world" @dbus_signal() def SignalComplex(self) -> "a{sv}": # noqa: F722 diff --git a/tests/service/test_decorators.py b/tests/service/test_decorators.py index 13a3b122..00eda6ce 100644 --- a/tests/service/test_decorators.py +++ b/tests/service/test_decorators.py @@ -24,7 +24,7 @@ def some_signal(self) -> "as": # noqa: F722 @dbus_signal(name="renamed_signal", disabled=True) def another_signal(self) -> "(dodo)": - return [1, "/", 1, "/"] + return (1, "/", 1, "/") @dbus_property( name="renamed_readonly_property", access=PropertyAccess.READ, disabled=True diff --git a/tests/service/test_methods.py b/tests/service/test_methods.py index 203063be..5d8b289a 100644 --- a/tests/service/test_methods.py +++ b/tests/service/test_methods.py @@ -27,7 +27,7 @@ def echo(self, what: "s") -> "s": @dbus_method() def echo_multiple(self, what1: "s", what2: "s") -> "ss": assert type(self) is ExampleInterface - return [what1, what2] + return what1, what2 @dbus_method() def echo_containers( @@ -38,7 +38,7 @@ def echo_containers( struct: "(s(s(v)))", ) -> "asva{sv}(s(s(v)))": # noqa: F722 assert type(self) is ExampleInterface - return [array, variant, dict_entries, struct] + return array, variant, dict_entries, struct @dbus_method() def ping(self): @@ -75,7 +75,7 @@ async def echo(self, what: "s") -> "s": @dbus_method() async def echo_multiple(self, what1: "s", what2: "s") -> "ss": assert type(self) is AsyncInterface - return [what1, what2] + return what1, what2 @dbus_method() async def echo_containers( @@ -86,7 +86,7 @@ async def echo_containers( struct: "(s(s(v)))", ) -> "asva{sv}(s(s(v)))": # noqa: F722 assert type(self) is AsyncInterface - return [array, variant, dict_entries, struct] + return array, variant, dict_entries, struct @dbus_method() async def ping(self): diff --git a/tests/service/test_signals.py b/tests/service/test_signals.py index 5c3c9a6c..0a10554c 100644 --- a/tests/service/test_signals.py +++ b/tests/service/test_signals.py @@ -30,7 +30,7 @@ def signal_simple(self) -> "s": @dbus_signal() def signal_multiple(self) -> "ss": assert type(self) is ExampleInterface - return ["hello", "world"] + return "hello", "world" @dbus_signal(name="renamed") def original_name(self):