[issue25564] IDLE behaves differently than python on `del __builtins__`

Terry J. Reedy report at bugs.python.org
Fri Nov 6 03:37:07 EST 2015


Terry J. Reedy added the comment:

We try to have IDLE work the same as Python (and CPython, where relevant), except where differences are intentional or unavoidable.  I am trying to eliminate some unintentional avoidable differences in other issues.  However, this one is unavoidable given IDLE's basic design.  Also, Steven is correct; see
https://docs.python.org/3/library/builtins.html#module-builtins

IDLE executes user code with "exec(code, self.locals)" (run.py, l.351 in 3.5).
https://docs.python.org/3/library/functions.html#exec
says "If the globals dictionary does not contain a value for the key __builtins__, a reference to the dictionary of the built-in module builtins is inserted under that key."

(Doc issus: From the builtins doc and the Jython example, this seems implementation dependent. Steven, does
  >>> d = {}; exec('', d); d.keys()
  dict_keys(['__builtins__'])
have this result in Jython?)

In the IDLE shell, each statement is exec'ed separately.  With two statements, __builtins__ is added back before 'min' , while with one statement, it is not.  

Editor: Run Module execs the entire file at once.  I expected print(min) to fail either way, but it works either way.  I verified that globals().keys() lost '__builtins__', so I don't know how __builtins__.min is found.

I left this open to consider adding a line to
https://docs.python.org/3/library/idle.html#idle-console-differences

----------
assignee:  -> terry.reedy
components: +Documentation
stage:  -> needs patch
title: IDLE behaves differently that the standard interpreter when someone types `del __builtins__` -> IDLE behaves differently than python on `del __builtins__`
type:  -> behavior
versions: +Python 3.4, Python 3.5, Python 3.6

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


More information about the Python-bugs-list mailing list