GNOME Bugzilla – Bug 652136
Make callbacks behave like signals for user_data
Last modified: 2013-02-20 10:54:04 UTC
To bind a signal to a callback, you do something like: def my_callback(<signal_args>, foo, bar): pass my_object.connect("some-signal", my_callback, foo, bar) If you don't have any user data to pass to your callback, you could do: def my_callback(<signal_args>): pass my_object.connect("some-signal", my_callback) I would like to be able to do that for the asynchronous functions of grilo, but there doesn't seem to be a way to do that properly. For instance, with the following function: guint grl_media_source_search (GrlMediaSource *source, const gchar *text, const GList *keys, guint skip, guint count, GrlMetadataResolutionFlags flags, GrlMediaSourceResultCb callback, gpointer user_data); The callback type is: typedef void (*GrlMediaSourceResultCb) (GrlMediaSource *source, guint operation_id, GrlMedia *media, guint remaining, gpointer user_data, const GError *error); In python, even if I don't have any user_data to pass, I need to do: def my_callback(source, op_id, media, remaining, user_data, error): pass my_media_source.search("blah", [<some keys>], 0, 0, <some flags>, my_callback, None, err) I would like to be able to get rid of that user_data param.
Part of this can be done with https://bugzilla.gnome.org/show_bug.cgi?id=558620: specifying "None" as user_data won't be needed in the initial call. Not sure whether we can easily support the removal of the parameter on the callback side, and whether this is really something we want to do anyway.
I'm inclined to close this as "won't fix", as otherwise we would need some heuristics which gpointer arguments can be skipped (and default to None) and which can't. Keeping as wishlist for now.
Marking as a dup because bug 640812 specifies the same thing but for any arg which allows null, which would include user_data. *** This bug has been marked as a duplicate of bug 640812 ***