Bug 34895

Summary: Cannot call overloaded dbus methods using dbus-python
Product: dbus Reporter: himthingwatsit
Component: pythonAssignee: Simon McVittie <smcv>
Status: RESOLVED FIXED QA Contact: John (J5) Palmieri <johnp>
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Bug Depends on: 36206    
Bug Blocks:    
Attachments: allows dbus-python users to call overloaded methods
allows dbus-python users to call overloaded methods

Description himthingwatsit 2011-03-01 22:19:16 UTC
Created attachment 43999 [details] [review]
allows dbus-python users to call overloaded methods

Using some dbus bindings (eg the qt bindings) it is possible to define multiple methods on the same interface with the same name and different type signatures.
Currently, dbus-python does not handle this case properly.

For example if an interface defines two methods:
Blah(string)
Blah(int32)

It will only be possible to call one of these methods using dbus-python, whichever was processed last when dbus-python read the xml introspection data.

Attached is a patch that should fix this issue.
Comment 1 himthingwatsit 2011-03-02 00:42:49 UTC
Created attachment 44007 [details] [review]
allows dbus-python users to call overloaded methods

The original patch would raise an exception complaining about ambiguous method calls if there were multiple candidate methods.

ie if we have an interface defining the methods:
Blah(string)
Blah(int32)
Blah(int64)

then calling Blah(123) would raise an exception because it can't tell whether to call Blah(int32) or Blah(int64).

I removed this because it may break some pre-existing scripts. It will now just call the last valid method.
Comment 2 Simon McVittie 2011-05-17 10:49:28 UTC
I think the only correct way to call an overloaded method would be to use signature='x' explicitly, but that's blocked by Bug #36206.
Comment 3 Simon McVittie 2011-05-18 04:35:39 UTC
I think the right way to call overloaded methods is to use the new support for the signature='x' keyword argument (which will be available from dbus-python 0.84 onewards) on method calls: "explicit is better than implicit" and "when faced with ambiguity, resist the temptation to guess".

So you'd use:

    myproxy.Blah('foo', signature='s')
    myproxy.Blah(42, signature='i')

This bypasses introspection completely (which is good, because dbus-python's existing use of introspection also violates those design principles).

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.