[issue33547] Relative imports do not replace local variables

R. David Murray report at bugs.python.org
Wed May 16 17:40:02 EDT 2018


R. David Murray <rdmurray at bitdance.com> added the comment:

It's importing 'a' from '.', which I guess in this context means from the current namespace (__main__), and a is 7.  You'll note that 'b' did get repointed, but it got repointed to what 'a' points to, instead of to 5.  If it really wasn't replacing the local, you'd get '7 5', not '7 7'.

So, this is weird but expected, I think.  You'll have to actually produce the example that doesn't involve __main__ if you want us to look in to that, but most likely it will be some similar phenomenon.

I'm not 100% sure this is the *desired* behavior of 'from . import', though, so I'm leaving this open for the import experts to look at.

Also, in 3.8 at least I get a warning from the import system, which is a clue something weird is going on :)

----------
nosy: +brett.cannon, eric.snow, ncoghlan, r.david.murray

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33547>
_______________________________________


More information about the Python-bugs-list mailing list