[Python-ideas] Module aliases and/or "real names"

Ron Adam rrr at ronadam.com
Fri Jan 7 03:38:07 CET 2011



On 01/05/2011 07:52 PM, Nick Coghlan wrote:
> On Thu, Jan 6, 2011 at 3:45 AM, Michael Foord<fuzzyman at voidspace.org.uk>  wrote:
>> On 5 January 2011 15:57, Nick Coghlan<ncoghlan at gmail.com>  wrote:
>>> The two examples I looked at (functools and datetime) favoured hiding
>>> the implementation details at the cost of causing introspection
>>> problems. Despite my comments in the opening post of the thread, I
>>> think that is the better trade-off to make.
>>
>> Both of those are because of underlying C implementations where
>> introspection problems would be the default anyway, which isn't quite the
>> same for situation for unittest.
>
> True, but it means the precedent of using __module__ to refer to the
> official location rather than than the actual location has already
> been set. That suggests to me our best way forward is to bless that as
> a recommended practice, then find a way to deal with the negative
> impact it currently has on introspection (such as a "__real_module__"
> attribute, as I suggested in another post).

You could add a private dictionary to sys, that is updated along with 
sys.modules, which maps module names to real names.  And have a function in 
inspect to retrieve the real name for an object.

That sounds like it would do pretty much what you need and doesn't add a 
top level builtin or global, or change "if __name__ == '__main__': main()".

Cheers,
   Ron




More information about the Python-ideas mailing list