[New-bugs-announce] [issue17953] sys.modules cannot be reassigned

ProgVal report at bugs.python.org
Sat May 11 10:23:33 CEST 2013


New submission from ProgVal:

In Python 3.3 (I did not test with 3.4), sys.modules cannot be reassigned without breaking the import mechanism; while it works with Python <= 3.2.

Here is how to reproduce the bug:

progval at Andromede:/tmp$ mkdir test_imports
progval at Andromede:/tmp$ echo "from . import module" > test_imports/__init__.py
progval at Andromede:/tmp$ echo "print('foo')" > test_imports/module.py
progval at Andromede:/tmp$ python3.3
Python 3.3.1 (default, Apr  6 2013, 13:58:40) 
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.modules = dict(sys.modules)
>>> import test_imports
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./test_imports/__init__.py", line 1, in <module>
    from . import module
SystemError: Parent module 'test_imports' not loaded, cannot perform relative import
>>> 
progval at Andromede:/tmp$ python3.2
Python 3.2.3 (default, May  6 2013, 01:46:35) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.modules = dict(sys.modules)
>>> import test_imports
foo
>>>

----------
components: Interpreter Core
messages: 188901
nosy: Valentin.Lorentz
priority: normal
severity: normal
status: open
title: sys.modules cannot be reassigned
type: behavior
versions: Python 3.3

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


More information about the New-bugs-announce mailing list