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 638523 - Events not handled by the event override go into infinite recursion on bad attribute names
Events not handled by the event override go into infinite recursion on bad at...
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
Git master
Other Linux
: Normal normal
: ---
Assigned To: Simon van der Linden
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-01-02 17:25 UTC by Mike Auty
Modified: 2011-01-07 11:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Don't call getattr again in gi.overrides.Gdk.Event.__getattr__ (1.20 KB, patch)
2011-01-02 18:31 UTC, Simon van der Linden
committed Details | Review

Description Mike Auty 2011-01-02 17:25:04 UTC
So, I ran into this problem when trying to handle a scroll event.  Probably the easiest description would be a small test script that exhibits the problem:

Steps to reproduce
------------------

from gi.repository import Gdk
# Creates an even with type GDK_SCROLL, as a normal scroll event would have
x = Gdk.Event()
x.type = Gdk.EventType.SCROLL
print x.unknownattribute

Expected result
---------------

Traceback (most recent call last):
  • File "<stdin>", line 1 in <module>
  • File "/usr/lib/python2.7/site-packages/gtk-2.0/gi/overrides/Gdk.py", line 113 in __getattr__
    return getattr(getattr(self, real_event), name)
AttributeError: 'EventAny' object has no attribute 'unknownattribute'

Actual Result
-------------

...
  File "/usr/lib/python2.7/site-packages/gtk-2.0/gi/overrides/Gdk.py", line 115, in __getattr__
    return getattr(self, name)
  File "/usr/lib/python2.7/site-packages/gtk-2.0/gi/overrides/Gdk.py", line 111, in __getattr__
    real_event = getattr(self, '_UNION_MEMBERS').get(self.type)
RuntimeError: maximum recursion depth exceeded while calling a Python object


This seems to occur in the Event override wrapper in the __getattr__ function because if a real_event can't be retrieved from the _UNION_MEMBERS list, then it calls getattr on itself, which goes round in circles.  If you need any further information, please let me know and I'll be happy to provide it...
Comment 1 Simon van der Linden 2011-01-02 18:31:02 UTC
Created attachment 177365 [details] [review]
Don't call getattr again in gi.overrides.Gdk.Event.__getattr__

__getattr__ is only called when the attribute is not found through the normal
mechanism, so getattr must not be called again in __getattr__ (which would
create an infinite loop).

Another possibility would be to implement __getattribute__ instead, which is
called in place of the normal mechanism. In that case, calling getattr would be
needed for normal attributes.
Comment 2 johnp 2011-01-04 16:49:47 UTC
Comment on attachment 177365 [details] [review]
Don't call getattr again in gi.overrides.Gdk.Event.__getattr__

Can we have a test for this?
Comment 3 Tomeu Vizoso 2011-01-07 11:59:14 UTC
Attachment 177365 [details] pushed as 204b45c - Don't call getattr again in gi.overrides.Gdk.Event.__getattr__