[py-svn] py-trunk commit 92f94395f31c: porting latest apipkg

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sun Jan 10 13:57:39 CET 2010


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1263128095 -3600
# Node ID 92f94395f31c1e99a0db0300599e26f130b192d5
# Parent 63aaeba61e94b4fac8f53964cdc1ba25794626e0
porting latest apipkg

--- a/py/apipkg.py
+++ b/py/apipkg.py
@@ -55,7 +55,8 @@ class ApiModule(ModuleType):
             return '<ApiModule %r %s>' % (self.__name__, " ".join(l))
         return '<ApiModule %r>' % (self.__name__,)
 
-    def __getattr__(self, name):
+    def __makeattr(self, name):
+        """lazily compute value for name or raise AttributeError if unknown."""
         target = None
         if '__onfirstaccess__' in self.__map__:
             target = self.__map__.pop('__onfirstaccess__')
@@ -73,6 +74,8 @@ class ApiModule(ModuleType):
             del self.__map__[name]
             return result
 
+    __getattr__ = __makeattr
+
     def __dict__(self):
         # force all the content of the module to be loaded when __dict__ is read
         dictdescr = ModuleType.__dict__['__dict__']
@@ -80,6 +83,9 @@ class ApiModule(ModuleType):
         if dict is not None:
             hasattr(self, 'some')
             for name in self.__all__:
-                hasattr(self, name)  # force attribute load, ignore errors
+                try:
+                    self.__makeattr(name)
+                except AttributeError:
+                    pass
         return dict
     __dict__ = property(__dict__)



More information about the pytest-commit mailing list