New submission from Brett Cannon:

If you look at things like https://github.com/kennethreitz/requests/issues/2870 
and https://pythonhosted.org/six/#module-six.moves you start to notice that 
users do on occasion have a need to alias module names. It might be worth 
thinking through what that might entail and provide a solution.

Historically it has been done with a meta path importer which catches the 
import for some old module name, imports the real name, and then sets 
sys.modules under the alternative name before returning that the import was 
successful. It's a little tricky to get right, though, since you essentially 
have to pause an import while another one is going on, make sure you wait to 
the last minute to do the sys.modules aliasing to make sure no object swap 
handled from underneath you. I also have not thought through the best way to do 
this with module specs., but maybe there is a better way. There's also making 
sure locking is handled properly.

The reason this might be useful to have in importlib is it would help 
facilitate module renamings. If you set it up so that it isn't hard to turn on 
with mappings of old name to new along with whether you want to raise an 
ImportWarning about the aliasing then others may find it useful.

----------
components: Library (Lib)
messages: 254805
nosy: brett.cannon
priority: normal
severity: normal
stage: test needed
status: open
title: Come up with a good way to handle module aliasing
type: enhancement
versions: Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25649>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to