DynamicModule getattr implementation
- From: Daniel Drake <dsd laptop org>
- To: "python-hackers-list gnome org" <python-hackers-list gnome org>
- Subject: DynamicModule getattr implementation
- Date: Wed, 17 Jul 2013 15:54:19 -0600
Hi,
I am looking at possibilities for speeding up overrides loading (i.e.
how to make it avoid loading *all* the stuff for overriden classes
during startup, could be done lazily?) but I'm a bit stuck in trying
to understand DynamicModule's getattr implementation.
def __getattr__(self, name):
if self._overrides_module is not None:
override_exports = getattr(self._overrides_module, '__all__', ())
if name in override_exports:
return getattr(self._overrides_module, name, None)
else:
# check the registry just in case the module hasn't loaded yet
# TODO: Only gtypes are registered in the registry right now
# but it would be nice to register all overrides and
# get rid of the module imports. We might actually see a
# speedup.
key = '%s.%s' % (self._namespace, name)
if key in registry:
return registry[key]
Taking the Gtk.Widget override as an example. The class is registered
at gi.overrides.Gtk.Widget so the first override_exports check will
find it.
In fact, I cannot see any case in which the overriden item would *not*
be found with that check. So is the registry pointless?
I would vote for removing the registry, but that comment is
interesting since it mentions "speedup". I don't understand the
comment though. It says "in case the module hasn't loaded" - is it
referring to the override module here? Under what circumstances could
that be true if the override module is the thing that places items in
the registry? Is there still scope for a speedup here?
Thanks
Daniel
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]