[patch][python] Fix fd.o #10174: make it possible to return multiple values with no signature.

John (J5) Palmieri johnp at redhat.com
Tue Apr 24 12:54:53 PDT 2007


On Tue, 2007-04-24 at 18:16 +0100, Simon McVittie wrote:
> >From ae8014c72a7d304f20d9422009f42bc48fa8f298 Mon Sep 17 00:00:00 2001
> From: Simon McVittie <simon.mcvittie at collabora.co.uk>
> Date: Tue, 24 Apr 2007 17:45:03 +0100
> Subject: [PATCH] Fix fd.o #10174: make it possible to return multiple values with no signature.
> More specifically: when a service method with no signature synchronously
> returns a tuple that is not a Struct, interpret it as a multi-valued return,
> rather than as a structure.
> 
> This is a common Python idiom, and returning a struct makes little sense
> anyway when D-Bus lets you return multiple values.
> 
> Returned lists are still interpreted as arrays - returning an array is
> entirely sensible, and indeed likely to be common.
> 
> Async service methods are unaffected (there is no ambiguity), and it's still
> possible to return a structure by returning a dbus.Struct with appropriate
> contents.
> 
> https://bugs.freedesktop.org/show_bug.cgi?id=10174
> ---
>  dbus/service.py      |    8 +++++++-
>  test/test-client.py  |    6 ++++++
>  test/test-service.py |    5 +++++
>  3 files changed, 18 insertions(+), 1 deletions(-)
> 
> diff --git a/dbus/service.py b/dbus/service.py
> index 775133f..2557de0 100644
> --- a/dbus/service.py
> +++ b/dbus/service.py
> @@ -486,8 +486,14 @@ class Object(Interface):
>  
>              # no signature, so just turn the return into a tuple and send it as normal
>              else:
> -                if retval == None:
> +                if retval is None:
>                      retval = ()
> +                elif (isinstance(retval, tuple)
> +                      and not isinstance(retval, _dbus_bindings.Struct)):
> +                # If the return is a tuple that is not a Struct, we use it
> +                # as-is on the assumption that there are multiple return
> +                # values - this is the usual Python idiom. (fd.o #10174)
> +                    pass
>                  else:
>                      retval = (retval,)
>  

Looks good.

-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list