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 646667 - The '__info__' override is not well controlled
The '__info__' override is not well controlled
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gio
Git master
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-04-04 00:24 UTC by Juanje Ojeda
Modified: 2012-04-04 14:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch for better controlling the KeyErrors on gi.override (1.03 KB, patch)
2011-04-04 00:24 UTC, Juanje Ojeda
needs-work Details | Review

Description Juanje Ojeda 2011-04-04 00:24:02 UTC
Created attachment 185067 [details] [review]
Patch for better controlling the KeyErrors on gi.override

If I try the code:
<code>
import gtk
from gi.repository import Gio
</code>

I get this error:
<code>
Traceback (most recent call last):
  • File "/tmp/gi_repository_test.py", line 2 in <module>
    from gi.repository import Gio
  • File "/home/jojeda/releases/gnome-apps-2.91.93/install/lib/python2.6/site-packages/gi/importer.py", line 76 in load_module
    dynamic_module._load()
  • File "/home/jojeda/releases/gnome-apps-2.91.93/install/lib/python2.6/site-packages/gi/module.py", line 242 in _load
    overrides_modules = __import__('gi.overrides', fromlist=[self._namespace])
  • File "/home/jojeda/releases/gnome-apps-2.91.93/install/lib/python2.6/site-packages/gi/overrides/Gio.py", line 48 in <module>
    FileEnumerator = override(FileEnumerator)
  • File "/home/jojeda/releases/gnome-apps-2.91.93/install/lib/python2.6/site-packages/gi/overrides/__init__.py", line 63 in override
    registry.register(type_)
  • File "/home/jojeda/releases/gnome-apps-2.91.93/install/lib/python2.6/site-packages/gi/overrides/__init__.py", line 38 in register
    self[override_class] = override_class
  • File "/home/jojeda/releases/gnome-apps-2.91.93/install/lib/python2.6/site-packages/gi/overrides/__init__.py", line 20 in __setitem__
    info = getattr(value, '__info__')
AttributeError: type object 'FileEnumerator' has no attribute '__info__'
</code>

I know there are some issues using old gtk and introspection, that's not the bug, the bug is that there is a 'raise' statement for controlling when a type object has no attribute '__info__' with some nice error message and some info, but it won't ever be shown because the 'getattr' from the line before is going to launch its own exception.

As far I know, this is happening with Gio and Pango.

I'll attach a patch which will make this more clear.
Comment 1 Johan (not receiving bugmail) Dahlin 2011-04-04 01:49:56 UTC
Comment on attachment 185067 [details] [review]
Patch for better controlling the KeyErrors on gi.override

>From 144fe78d76331c5510fd57ea50c0225faa2e3a27 Mon Sep 17 00:00:00 2001
>From: Juanje Ojeda <jojeda@emergya.es>
>Date: Mon, 4 Apr 2011 01:18:43 +0100
>Subject: [PATCH] [gi-overrides] Added try statement for checking the __info__ attrib from the module
>
>---
> gi/overrides/__init__.py |    5 +++--
> 1 files changed, 3 insertions(+), 2 deletions(-)
>
>diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
>index a98974f..6de2ac4 100644
>--- a/gi/overrides/__init__.py
>+++ b/gi/overrides/__init__.py
>@@ -17,8 +17,9 @@ class _Registry(dict):
>         if not key == value:
>             raise KeyError('You have tried to modify the registry.  This should only be done by the override decorator')
> 
>-        info = getattr(value, '__info__')
>-        if info == None:

if getattr(value, '__info__', None) is None:

Is a better/shorter version of this.
Comment 2 Juanje Ojeda 2011-04-04 18:14:42 UTC
(In reply to comment #1)

> > 
> >-        info = getattr(value, '__info__')
> >-        if info == None:
> 
> if getattr(value, '__info__', None) is None:
> 
> Is a better/shorter version of this.

Maybe a intermediate solution in order to be more clear? Just saying...


-        info = getattr(value, '__info__')
-        if info == None:
+        info = getattr(value, '__info__', None)
+        if info is None:
             raise KeyError('Can not override a type %s, which is not in a gobject introspection typelib' % value.__name__)
Comment 3 Martin Pitt 2012-04-04 14:01:27 UTC
Thanks for this!

I cleaned up the patch and added a test case. While I was at it, I also fixed the exception. KeyError makes no sense there, TypeError is more appropriate.

http://git.gnome.org/browse/pygobject/commit/?id=05030a95a4d3090162ed5f510a26d69bbb152942