renaming imports

Marc Wachowitz (mw@ipx2.rz.uni-mannheim.de)
1 Feb 1995 10:23:17 GMT

It would be nice if the import statement (in both variants) could specify
the local name for the importet entities; something like the following (I
guess the desired semantics is clear):

import local_1 = external_1, local_2 = external_2
from module import local_1 = external_1, local_2 = external_2

The current form would then simply be an abbreviation. The external names
would never appear in the importing scope (unless they are equal to local
names, of course).

The intended benefit is both avoiding name space pollution and not having
to worry whether an exported entity should include the module's name. I'm
often doing the following in the current system, but I'd like to simplify
it:

import module
module__entity_1 = module.entity_1
module__entity_2 = module.entity_2

The cause for not using module.entity everywhere is an additional lookup,
which would take some unnecessary time in tight loops. Currently I'm only
doing this for heavily used imported entities, but it's an easy way to be
less dynamic in cases where no variable data is expected. (Hmm, that also
makes me think about non-alterable bindings, but that's another topic.) I
would prefer to write:

from module import module__entity_1 = entity_1, module__entity_2 = entity_2

A support for the style of a common prefix (here the module name plus "__")
would also be nice, but I guess that's too much to ask? ;-) This could then
be done with:

from module import ( module__ ) entity_1, entity_2

(The prefix shouldn't be fixed to be of this form; any identifier is ok.)

------------------------------------------------------------------------------
* wonder everyday * nothing in particular * all is special *
Marc Wachowitz <mw@ipx2.rz.uni-mannheim.de>