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 712519 - GLib.GError inconsistencies
GLib.GError inconsistencies
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
3.10.x
Other Linux
: Normal minor
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2013-11-16 19:54 UTC by Christoph Reiter (lazka)
Modified: 2014-05-05 07:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add Python implementation of GError (8.12 KB, patch)
2014-05-05 06:51 UTC, Simon Feltman
committed Details | Review
Simplify pygi_error_marshal to use GError initializer arguments (1.93 KB, patch)
2014-05-05 07:02 UTC, Simon Feltman
committed Details | Review
Clobber GLib.Error with custom implementation (8.52 KB, patch)
2014-05-05 07:27 UTC, Simon Feltman
committed Details | Review

Description Christoph Reiter (lazka) 2013-11-16 19:54:17 UTC
Some minor GLib.GError related issues:

################################################################

>>> GLib.GError
<class 'gi._glib.GError'>

>>> GLib.GError is GLib.Error
False

>>> type(GLib.Error.new_literal(1,1,"")) is GLib.GError
True

Traceback (most recent call last):
  • File "a.py", line 3 in <module>
    doc = P.Document.new_from_file('file:///path/to/a/.pdf', '')
gi._glib.GError: No such file or directory

################################################################

* It would be nice it GLib.Error was the same as GLib.GError since only GError can be used to catch exceptions atm. This probably needs implementation of the GLib.Error methods/fields in C to keep it API compatible (??)

* It would be nice if the class name of the internal GError class was "GLib.[G]Error" so it would be obvious how to catch the exception based on the traceback. This should be easy I guess.
Comment 1 Simon Feltman 2013-11-17 00:14:31 UTC
(In reply to comment #0)
> It would be nice it GLib.Error was the same as GLib.GError since only GError
> can be used to catch exceptions atm. This probably needs implementation of the
> GLib.Error methods/fields in C to keep it API compatible (??)

Agreed. The "code" and "domain" fields could just be added to the existing GError class and marshaling should probably fill them out as well:
https://git.gnome.org/browse/pygobject/tree/gi/_glib/glibmodule.c?id=3.11.1#n76

We could then just clobber GLib.Error with GLib.GError and monkey patch methods in the GLib overrides.
Comment 2 Gian Mario Tagliaretti 2013-11-30 21:26:42 UTC
At the moment methods like g_error_matches are implemented into GLib.Error

In [4]: GLib.Error.matches
Out[4]: <gi.FunctionInfo object (matches) at 0x0xb5ceb340>

and not in GLib.GError

In [3]: GLib.GError.matches
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-da6a08a89fa1> in <module>()
----> 1 GLib.GError.matches
AttributeError: type object 'GError' has no attribute 'matches'

but in some cases such as the signal "parsing-error" of Gtk.CssProvider a GLib.GError is returned

gi._glib.GError: <data>:13:13'gree' is not a valid color name
<class 'gi._glib.GError'>

so it's impossibile to use the above g_error_matches from pygobject
Comment 3 Simon Feltman 2014-05-04 07:53:45 UTC
Some initial cleanup to get this started has been committed here:
https://git.gnome.org/browse/pygobject/commit/?id=649895d

The plan is to add a more complete static binding of GError that will clobber GLib.Error and hold a pointer to a C GError. Since GLib.Error is derived from gi.Boxed, we can never really use this in combination with Pythons builtin Exception class.
Comment 4 Simon Feltman 2014-05-05 06:51:27 UTC
The following fix has been pushed:
3083daf Add Python implementation of GError
Comment 5 Simon Feltman 2014-05-05 06:51:31 UTC
Created attachment 275864 [details] [review]
Add Python implementation of GError

Add internally used gi/_error.py module as a basis for implementing
a unified GError between introspection and static bindings. Patch Python
implementations of GError.matches and GError.new_literal in the GLib
overrides
Comment 6 Simon Feltman 2014-05-05 07:02:07 UTC
The following fix has been pushed:
f80f5ec Simplify pygi_error_marshal to use GError initializer arguments
Comment 7 Simon Feltman 2014-05-05 07:02:10 UTC
Created attachment 275866 [details] [review]
Simplify pygi_error_marshal to use GError initializer arguments
Comment 8 Simon Feltman 2014-05-05 07:27:04 UTC
The following fix has been pushed:
4c2e691 Clobber GLib.Error with custom implementation
Comment 9 Simon Feltman 2014-05-05 07:27:07 UTC
Created attachment 275867 [details] [review]
Clobber GLib.Error with custom implementation

Clobber the introspection GLib.Error class with the custom Python
implementation found in gi._error.GError. Update references to GLib.GError
to use GLib.Error.