Terry J. Reedy added the comment:
The bug is not in Idle. Its interpreter is a subclass of
code.InteractiveInterpreter (II) and that (and its subclass InteractiveConsole)
have the bug.
C:\Programs\Python33>python -m code
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> def a():
... def b():
... nonlocal c
File "<string>", line None
SyntaxError: no binding for nonlocal 'c' found
II.runsource compiles cumulative source with codeop.CommandCompile, which wraps
codeop._maybe_compile. That returns None (source incomplete), raises (source
complete but invalid), or return code (source complete and valid) to be
executed. It mis-classifies the code in question.
>>> import codeop as op
>>> src = '''def a():
def b():
nonlocal c
'''
>>> op.CommandCompiler()(src)
Traceback (most recent call last):
...
SyntaxError: no binding for nonlocal 'c' found
PyShell.ModifiedInterpreter.runsource wraps II.runsource.
return InteractiveInterpreter.runsource(self, source, filename)
Someone needs to compare _maybe_compile to the equivalent C code used by the
real interpreter.
----------
components: +Library (Lib) -IDLE
title: IDLE over-enthusiastically verifies 'nonlocal' usage -> codeop
misclassifies incomple code with 'nonlocal'
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue19335>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com