[py-svn] apipkg commit 78ac2d06cf0b: remove the __fullname__ attribute, __name__ is now the expected doted name

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Oct 27 21:04:51 CET 2009


# HG changeset patch -- Bitbucket.org
# Project apipkg
# URL http://bitbucket.org/hpk42/apipkg/overview/
# User Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
# Date 1256300292 -7200
# Node ID 78ac2d06cf0b8e9dc445f8c72dd637fa643a59b5
# Parent 9fee4ebc2b037921b0bff990052ddae0d7265060
remove the __fullname__ attribute, __name__ is now the expected doted name

--- a/test_apipkg.py
+++ b/test_apipkg.py
@@ -154,3 +154,9 @@ def test_initpkg_do_replace(monkeypatch)
     apipkg.initpkg('email_replace', {}, replace=True)
     assert sys.modules['email_replace'] is not api
 
+def test_name_attribute():
+    api = apipkg.ApiModule('name_test', {
+        'subpkg': {},
+        })
+    assert api.__name__ == 'name_test'
+    assert api.subpkg.__name__ == 'name_test.subpkg'

--- a/apipkg.py
+++ b/apipkg.py
@@ -28,16 +28,12 @@ class ApiModule(ModuleType):
         self.__name__ = name
         self.__all__ = list(importspec)
         self.__map__ = {}
-        if parent:
-            fullname = parent.__fullname__ + "." + name
-            setattr(parent, name, self)
-        else:
-            fullname = name
-        self.__fullname__ = fullname
         for name, importspec in importspec.items():
             if isinstance(importspec, dict):
-                apimod = ApiModule(name, importspec, parent=self)
-                sys.modules[apimod.__fullname__] = apimod
+                package = '%s.%s'%(self.__name__, name)
+                apimod = ApiModule(package, importspec, parent=self)
+                sys.modules[package] = apimod
+                setattr(self, name, apimod)
             else:
                 if not importspec.count(":") == 1:
                     raise ValueError("invalid importspec %r" % (importspec,))
@@ -45,11 +41,11 @@ class ApiModule(ModuleType):
                     self.__doc__ = importobj(importspec)
                 else:
                     if importspec[0] == '.':
-                        importspec = fullname + importspec
+                        importspec = self.__name__ + importspec
                     self.__map__[name] = importspec
 
     def __repr__(self):
-        return '<ApiModule %r>' % (self.__fullname__,)
+        return '<ApiModule %r>' % (self.__name__,)
 
     def __getattr__(self, name):
         try:



More information about the pytest-commit mailing list