After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 652136 - Make callbacks behave like signals for user_data
Make callbacks behave like signals for user_data
Status: RESOLVED DUPLICATE of bug 640812
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other All
: Low enhancement
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-06-08 19:03 UTC by Guillaume Emont (guijemont)
Modified: 2013-02-20 10:54 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Guillaume Emont (guijemont) 2011-06-08 19:03:48 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.
Comment 1 Guillaume Emont (guijemont) 2011-10-27 14:08:25 UTC
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.
Comment 2 Martin Pitt 2012-04-23 15:57:10 UTC
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.
Comment 3 Simon Feltman 2013-02-20 10:54:04 UTC
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 ***