[issue17636] Modify IMPORT_FROM to fallback on sys.modules

Kristján Valur Jónsson report at bugs.python.org
Fri Apr 5 15:07:42 CEST 2013


Kristján Valur Jónsson added the comment:

While I'm happy that this is being ackowledged as a problem, I'm not sure changing the "import x from y" semantics is necessarily a good idea.  I mean, it is obvious to me that it means "import x, then getattr(x, "y")".  I presume that is the meaning most people associate with it.  Certainly, "y" can be any old module attribute.

To change it to actually fall back to a submodule, well. I suppose if you could explain it roughly like "y = getattr(x, 'y', x.y)"  then it would be ok.

But I can think of contrived examples where this could break things:
#a.py:
from .b import util

#b.py
from . import a
from .util import util

Because of the circular import order, b.util will not exist as an attribute on b when a does its import.  So a.util will end up being util instead of util.util as one might expect.

I'm basically saying that it is possible that the fallback to submodule will occur, where the successful getattr would occur later and return something different than the submodule.  Possible. But perhaps very much an edge case :)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17636>
_______________________________________


More information about the Python-bugs-list mailing list