Commits

Ralf Schmitt committed 41f548c

simplify AliasModule.__repr__.

also do not use __name__, rather load it from the original module.

Comments (0)

Files changed (2)

 
 class AliasModule(ModuleType):
     def __init__(self, name, modpath):
-        self.__name__ = name
+        self.__name = name
         self.__modpath = modpath
 
     def __repr__(self):
-        l = []
-        if hasattr(self, '__version__'):
-            l.append("version=" + repr(self.__version__))
-        if hasattr(self, '__file__'):
-            l.append('from ' + repr(self.__file__))
-        if l:
-            return '<AliasModule %r %s>' % (self.__name__, " ".join(l))
-        return '<AliasModule %r>' % (self.__name__,)
+        return '<AliasModule %r for %r>' % (self.__name, self.__modpath)
 
     def __getattr__(self, name):
         mod = importobj(self.__modpath, None)
     monkeypatch.syspath_prepend(tmpdir)
     import extra_attributes
     assert extra_attributes.foo == 'bar'
+
+def test_aliasmodule_repr():
+    am = apipkg.AliasModule("mymod", "sys")
+    r = repr(am)
+    assert "<AliasModule 'mymod' for 'sys'>" == r
+    am.version
+    assert repr(am) == r