Author christian.heimes
Recipients christian.heimes
Date 2017-09-29.20:21:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1506716472.27.0.213398074469.issue31642@psf.upfronthosting.co.za>
In-reply-to
Content
Since Python 3.6, the blocking of imports is broken for 'from package import module' imports.

$ mkdir a
$ touch a/__init__.py a/b.py

>>> import sys
>>> sys.modules['a.b'] = None
>>> from a import b
>>> b is None
True
>>> import a.b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: import of 'a.b' halted; None in sys.modules

Tests with Python 2.7 to master:

$ python2.7 -c "from a import b; print(b)"
<module 'a.b' from 'a/b.py'>
$ python2.7 -c "import sys; sys.modules['a.b'] = None; from a import b"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name b
$ python2.7 -c "import sys; sys.modules['a.b'] = None; from a import b"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name b
$ python3.4 -c "import sys; sys.modules['a.b'] = None; from a import b"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: import of 'a.b' halted; None in sys.modules
$ python3.5 -c "import sys; sys.modules['a.b'] = None; from a import b"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: import of 'a.b' halted; None in sys.modules
$ python3.6 -c "import sys; sys.modules['a.b'] = None; from a import b"
$ ./python -c "import sys; sys.modules['a.b'] = None; from a import b"
History
Date User Action Args
2017-09-29 20:21:12christian.heimessetrecipients: + christian.heimes
2017-09-29 20:21:12christian.heimessetmessageid: <1506716472.27.0.213398074469.issue31642@psf.upfronthosting.co.za>
2017-09-29 20:21:12christian.heimeslinkissue31642 messages
2017-09-29 20:21:12christian.heimescreate