Re: lazy loading override classes



On Sun, Aug 11, 2013 at 6:00 PM, Simon Feltman <s feltman gmail com> wrote:
This is fine by me for the majority of overrides. When I first saw
your approach I momentarily thought about if we could use a straight
class decorator with metaclass magic, but I don't think it is possible
and your approach is more obvious. Out of curiosity did you attempt
other techniques or try any alternate approaches?

I did try one other approach.
At first when trying to understand why many types were being
initialized I thought it was this line:

class Widget(Gtk.Widget):

So I redefined Widget like this:

class Widget(object):

Then, when the Widget class is actually being used for the first time,
I used the type() inbuilt to make a new type with bases that
effectively made Widget inherit from Gtk.Widget, hopefully causing
Gtk.Widget to be initialised only at this late stage.

That didn't quite work as planned, Gtk.Widget was still being loaded
on import of the override module. The reason why can be seen if we
examine a bit more of the override:

class Widget(Gtk.Widget):
    translate_coordinates =
strip_boolean_result(Gtk.Widget.translate_coordinates)

Even if we remove the Gtk.Widget reference from the first line, the
second line still causes Gtk.Widget to be initialised during import of
the overrides module.

Thanks for your feedback, I will continue working on this.

Daniel


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]