GNOME Bugzilla – Bug 638523
Events not handled by the event override go into infinite recursion on bad attribute names
Last modified: 2011-01-07 11:59:18 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):
+ Trace 225370
return getattr(getattr(self, real_event), name)
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...
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 on attachment 177365 [details] [review] Don't call getattr again in gi.overrides.Gdk.Event.__getattr__ Can we have a test for this?
Attachment 177365 [details] pushed as 204b45c - Don't call getattr again in gi.overrides.Gdk.Event.__getattr__