[New-bugs-announce] [issue31642] None value in sys.modules no longer blocks import

Christian Heimes report at bugs.python.org
Fri Sep 29 16:21:12 EDT 2017


New submission from Christian Heimes <lists at cheimes.de>:

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"

----------
components: Interpreter Core
keywords: 3.6regression
messages: 303356
nosy: christian.heimes
priority: normal
severity: normal
status: open
title: None value in sys.modules no longer blocks import
versions: Python 3.6, Python 3.7, Python 3.8

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


More information about the New-bugs-announce mailing list