classification
Title: Deleting __import__ from builtins can crash Python3
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, brett.cannon, dmi.baranov, ezio.melotti, flox, python-dev
Priority: normal Keywords:

Created on 2013-04-29 10:15 by dmi.baranov, last changed 2013-04-29 13:08 by python-dev. This issue is now closed.

Messages (4)
msg188059 - (view) Author: Dmi Baranov (dmi.baranov) * Date: 2013-04-29 10:15
Simple case - let's delete __import__ and try to import anything

$ python3.3
Python 3.3.0 (default, Oct  7 2012, 11:03:52) 
[GCC 4.4.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> del __builtins__.__dict__['__import__']
>>> import os
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Fatal Python error: __import__ missing

Current thread 0x00007f07c9ebc700:
Aborted

But in python2.x

$ python2.7
Python 2.7.3 (default, Sep 22 2012, 02:37:18) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> del __builtins__.__dict__['__import__']
>>> import os
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: __import__ not found
>>>
msg188068 - (view) Author: Dmi Baranov (dmi.baranov) * Date: 2013-04-29 12:15
Another example of post-effects:

>>> del __builtins__.__dict__['__import__']
>>> 1/0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Fatal Python error: __import__ missing

Current thread 0x00007f3db64fd700:
Aborted
msg188069 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2013-04-29 12:50
Technically its not a crash but a fatal error. That's not to say its desirable, of course. :)
msg188070 - (view) Author: Roundup Robot (python-dev) Date: 2013-04-29 13:08
New changeset 08ce30768003 by Benjamin Peterson in branch '3.3':
raise an ImportError (rather than fatal) when __import__ is not found in __builtins__ (closes #17867)
http://hg.python.org/cpython/rev/08ce30768003
History
Date User Action Args
2013-04-29 13:08:42python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg188070

resolution: fixed
stage: test needed -> resolved
2013-04-29 12:50:02benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg188069
2013-04-29 12:15:14dmi.baranovsetmessages: + msg188068
2013-04-29 11:36:59floxsetnosy: + flox
2013-04-29 10:21:07ezio.melottisetnosy: + brett.cannon, ezio.melotti

stage: test needed
2013-04-29 10:15:23dmi.baranovcreate