# HG changeset patch -- Bitbucket.org # Project apipkg # URL http://bitbucket.org/hpk42/apipkg/overview # User Ralf Schmitt <r...@systemexit.de> # Date 1288905387 -3600 # Node ID 41f548cd98ae6bc5afa5da737730dda749646d76 # Parent ad8da71fea6dedc0757be6d7fedf7aa2e59362ce simplify AliasModule.__repr__.
also do not use __name__, rather load it from the original module. --- a/test_apipkg.py +++ b/test_apipkg.py @@ -393,3 +393,10 @@ def test_extra_attributes(tmpdir, monkey 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 --- a/apipkg.py +++ b/apipkg.py @@ -128,18 +128,11 @@ class ApiModule(ModuleType): 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) _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn