Skip to content
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

Support overloaded methods #82

Open
acetylen opened this issue Oct 15, 2018 · 0 comments
Open

Support overloaded methods #82

acetylen opened this issue Oct 15, 2018 · 0 comments

Comments

@acetylen
Copy link

I have a service written in C++, which has the following interface on D-Bus:

 <interface name="com.example.myservice1">
...
  <method name="publish">
    <arg name="data" type="(say)" direction="in"/>
  </method>  
  <method name="publish">
    <arg name="data" type="(say)" direction="in"/>
    <arg name="flag" type="(i)" direction="in"/>
  </method>
...
 </interface>

When interacting with the service, only the second method appears in the introspection data. Attempting to use the first method results in

>>> import pydbus
>>> a = pydbus.SessionBus()
>>> r = a.get('com.example.myservice', '/publisher1')
>>> r.publish((1, 'asdf', [1,2,3,4,5]))
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    r.publish((1, 'asdf', [1,2,3,4,5]))
  File ".../pydbus/proxy_method.py", line 62, in __call__
    raise TypeError(self.__qualname__ + " missing {} required positional argument(s)".format(-argdiff))
TypeError: com.example.myservice1.publish missing 1 required positional argument(s)

While attempting to use the second method results in a fairly useless

>>> r.publish((1, 'asdf', [1,2,3,4,5]), (0,))
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    r.publish((1, 'asdf', [1,2,3,4,5]), (0,))
  File ".../pydbus/proxy_method.py", line 74, in __ca
ll__
    self._iface_name, self.__name__, GLib.Variant(self._sinargs, args), GLib.VariantType.new(se
lf._soutargs),
  File "...gi/overrides/GLib.py", line 242, in __new__
    (v, rest_format, _) = creator._create(format_string, [value])
  File ".../gi/overrides/GLib.py", line 131, in _create
    return self._create_tuple(format, args)
  File ".../gi/overrides/GLib.py", line 166, in _create_tuple
    (v, format, _) = self._create(format, args[0][i:])
  File ".../gi/overrides/GLib.py", line 131, in _create
    return self._create_tuple(format, args)
  File ".../gi/overrides/GLib.py", line 170, in _create_tuple
    raise TypeError('tuple type string not closed with )')
TypeError: tuple type string not closed with )

I know this is due to Python's duck-typing approach, but I think creating multimethods when encountering overloaded functions may solve it elegantly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant