This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Rosuav, terry.reedy
Date 2013-10-22.03:19:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1382411950.95.0.346182960493.issue19335@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-10-22 03:19:10terry.reedysetrecipients: + terry.reedy, Rosuav
2013-10-22 03:19:10terry.reedysetmessageid: <1382411950.95.0.346182960493.issue19335@psf.upfronthosting.co.za>
2013-10-22 03:19:10terry.reedylinkissue19335 messages
2013-10-22 03:19:10terry.reedycreate