Skip to content
Draft
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
6 changes: 3 additions & 3 deletions docs/source/high-level-service/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <dbus_fast.DBusError>` to return a
Expand Down Expand Up @@ -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)'):
Expand Down
4 changes: 2 additions & 2 deletions examples/example-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion src/dbus_fast/_private/marshaller.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cdef class Marshaller:

cdef SignatureTree signature_tree
cdef bytearray _buf
cdef cython.list body
cdef object body

cdef _buffer(self)

Expand Down
2 changes: 1 addition & 1 deletion src/dbus_fast/_private/marshaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 7 additions & 5 deletions src/dbus_fast/_private/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/dbus_fast/aio/proxy_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions src/dbus_fast/glib/proxy_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
14 changes: 7 additions & 7 deletions src/dbus_fast/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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)

Expand All @@ -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.
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/dbus_fast/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/dbus_fast/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dbus_fast.DBusError>`
to return an error to the client.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
Expand All @@ -590,15 +590,15 @@ 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
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."""
Expand Down
5 changes: 2 additions & 3 deletions src/dbus_fast/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/client/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/client/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/service/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/service/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/service/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down