Terry J. Reedy <[email protected]> added the comment:
I verified that there are two discrepancies in IDLE versus the standard REPL on
Windows with 3.10.0a5. The latter first (which does not converted warnings to
errors).
Python 3.10.0a4+ (heads/master:0332e569c1, Feb 1 2021, 09:19:58) [MSC v.1900
64 bit (AMD64)] on win32
>>> x = 'a'
>>> x is 'a'
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
True
>>> if x is 'a': print('executed')
...
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
executed
versus, with IDLE,
>>> x = 'a'
>>> x is 'a' # No warning, also executed.
True
>>> if x is 'a': pass # Error instead of warning, hence not executed.
SyntaxError: "is" with a literal. Did you mean "=="?
There is no "IDLE parser" for interactive input. IDLE's Shell uses a subclass
of code.InteractiveInterpreter, which calls codeop.CommandCompiler. The latter
calls codeop._maybe_compile, which calls compile() 3 times for the source as
is, with '\n' appended, and with '\n\n' appended. #40807 fixed the issue of
getting 3 warnings instead of 1.
For the comparison "x is 'a'", all three compiles emit SyntaxWarning before
_maybe_compile returns a code object. The last two warnings are suppressed.
IDLE not printing Shell input warnings it is the subject of #37824.
Compiling the if statement without a final \n raises
SyntaxError: unexpected EOF while parsing
Adding '\n' results in the warning (converted to error in _maybe_compile) and a
code object.
I think there is a bug in the revised _maybe_compile but I need to add prints
or breakpoints to properly understand it. And have someone locate and explain
the REPL C code. If I decide _maybe_compile should be patched, I will open a
new issue.
---
PS Gary, when replying by email, please delete what you are responding to,
except possibly for a line or two. When posted on the web page below what you
respond to, the full quote is redundant noise.
Also, questions like 'How come?' should better be asked on python-list (or
other question-asking forums). Discussion there can lead to specific issues
here.
----------
assignee: -> terry.reedy
components: +IDLE
resolution: -> not a bug
stage: -> resolved
status: open -> closed
title: is with literals in 3.8 release -> SyntaxWarning for 'is <literal>'
type: -> behavior
versions: +Python 3.10
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue43151>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com