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 311226 - Metaclass registration causes breakage with old constructors
Metaclass registration causes breakage with old constructors
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
2.9.0
Other Linux
: High blocker
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2005-07-22 08:12 UTC by Mark McLoughlin
Modified: 2006-01-09 14:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
foodialog.py (273 bytes, patch)
2005-07-22 08:13 UTC, Mark McLoughlin
none Details | Review

Description Mark McLoughlin 2005-07-22 08:12:53 UTC
I haven't looked in detail at the problem yet, but it seems like the fix for bug
#161177 which introduces a new API for constructors breaks existing code.

E.g. if you run the attached test case, you get:

[markmc@blaa foo]$ python foodialog.py

** (foodialog.py:9081): WARNING **: Constructor wrapper for GtkMessageDialog
needs to be updated to the new API
Traceback (most recent call last):
  • File "foodialog.py", line 10 in ?
    FooDialog (None).run ()
  • File "foodialog.py", line 7 in __init__
    gtk.MessageDialog.__init__ (self, parent_window, 0, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK_CANCEL)
RuntimeError: __gobject_init__ must be used when subclassing gtk.MessageDialog

(Marking as a blocker since its API incompat, basically)
Comment 1 Mark McLoughlin 2005-07-22 08:13:32 UTC
Created attachment 49554 [details] [review]
foodialog.py
Comment 2 Gustavo Carneiro 2005-07-22 10:23:40 UTC
I've put this comment in the constructor for GtkMessageDialog:
      /* Note: with current API (gtk 2.4), it is impossible to
       * construct a GtkMessageDialog through g_object_new(), because
       * there is no 'message' property and the label field is
       * private */

I think it still applies.  The main problem is that there is no 'message'
property, nor there is gtk_message_dialog_set_message.  You have to use the
factory function..

In any case, since the constructor doesn't use g_object_new, I added that
check/exception to prevent more subtle bugs.  So, you should use
__gobject_init__ or GObject.__init__.  This is certainly not a regression from
2.6, and is unrelated to bug 161177.

Yes, there is a bug, but we can't fix without a new gtk+ API.  Unfortunately I
was too lazy to propose such an API in time... :P

But since you opened the bug, let's retitle it and leave it open.
Comment 3 Gustavo Carneiro 2005-07-22 10:55:05 UTC
OK, after so discussion I realize this problem is also related to metaclass
automatic registration.  While before you could use an old-style constructor if
you didn't register the subclass, now subclasses are implicitly registered,
which makes the GType for the subclass change and triggers that exception in the
gtk.MessageDialog constructor.  And indeed this is a regression; miraculously,
the code did work before!

A possible solution would be to, in the metaclass, check if neither
__gproperties__, __gsignals__, nor __gtype_name__ are defined, in which case we
skip registration.  Anyone against this?
Comment 4 Mark McLoughlin 2005-07-22 10:59:36 UTC
One problem - you'd need to allow people to explicitly call
gobject.type_register() on classes which don't have __gproperties__,
__gsignals__ or __gtype_name__ - i.e. you shouldn't get a deprecation warning in
that case.
Comment 5 Gustavo Carneiro 2005-07-22 11:18:42 UTC
Yes, this is already possible.  You don't get a deprecation warning now (2.7.x)
when calling gobject.type_register() on a subclass that wasn't registered.
Comment 6 Johan (not receiving bugmail) Dahlin 2005-07-22 12:49:40 UTC
I bug 311254 against Gtk+ which should solve the ::message problem, but we have
to wait until 2.10.

So there are two separate bug reports here,

1) Make it possible to subclass GtkMessageDialog's
2) Do not try to register a type twice.
Comment 7 Gustavo Carneiro 2005-07-22 13:22:47 UTC
Actually 2) should be:
"Do not automatically register a type if not needed."

def registration_is_needed(cls):
    return (hasattr(cls, "__gtype_name__") or hasattr(cls, "__gsignals__") or
hasattr(cls, "__gproperties__"))
Comment 8 Gustavo Carneiro 2005-07-22 14:07:18 UTC
Problem 2) got fixed in CVS the way I described.
Comment 9 Gustavo Carneiro 2005-07-30 16:05:04 UTC
Fixed also gobject.type_register deprecation warning; Now only a warning when
trying to register a type that is already registered.

Opened the MessageDialog problem as separate bug 312056.