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 cheryl.sabella, serhiy.storchaka, terry.reedy
Date 2020-06-04.19:05:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1591297512.44.0.221888165683.issue40807@roundup.psfhosted.org>
In-reply-to
Content
The purpose of code and codeop is to imitate interactive python in python.  Calling compile() thrice is an implementation detail.  Exposing that is a bug.  On #37824, Serhiy reported 3 'IDLE' bugs for 3.7 to 3.9: tripled DeprecationWarning (now joined by SyntaxWarning), printing to console (if available) instead of Shell, and an exit exception.  This issue is continuation of the triplicate issue, given that the bug is not in IDLE.  As a bug, I think it should still be backported.

I looked more carefully at the behavior of the standard REPL with different statement inputs.  Before executing, if the statement is complete, it may raise a compile exception, usually SyntaxError, or emit one or more a warnings, once for each instance.  For multiline statements, DeprecationWarnings are emitted immediately after the line with the deprecated code while SyntaxWarnings are emitted, if there is no syntax error, just before execution.  SyntaxWarnings for a given slice of code are not repeated.  However, at least some of these details have to be enforced in the UI code that repeatedly calls compile or _maybe_compile as lines are added, not in compile, and should not be in _maybe_compile.  Both have no memory or previous calls.  (I don't think that IDLE necessarily *must* do the same either.)

Looking at compile itself, it appears that warnings are not emitted if there is an exception.  But I am puzzled at this in 3.9 and master.

>>> if '\e' is 1:
<stdin>:1: DeprecationWarning: invalid escape sequence \e
...
versus
>>> compile('if '\e' is 1:\n', '', 'single')
  File "<stdin>", line 1
SyntaxError: unexpected character after line continuation character

Something must cause "'\e'" to be a warning instead of an error.

This is enough to experiment with your patch applied.
History
Date User Action Args
2020-06-04 19:05:12terry.reedysetrecipients: + terry.reedy, serhiy.storchaka, cheryl.sabella
2020-06-04 19:05:12terry.reedysetmessageid: <1591297512.44.0.221888165683.issue40807@roundup.psfhosted.org>
2020-06-04 19:05:12terry.reedylinkissue40807 messages
2020-06-04 19:05:11terry.reedycreate