[issue43151] is with literals in 3.8 release

2021-02-07 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

Terry, this may be an IDLE issue, can you confirm whether or not the difference 
in behaviour is intentional?

--
nosy: +terry.reedy
resolution: not a bug -> 
stage: resolved -> 
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43151] is with literals in 3.8 release

2021-02-07 Thread Gary Litvin


Gary Litvin  added the comment:

I noticed it in IDLE 3.8. I installed 3.8 because it is a fairly 
recent release described as "stable." Thanks to everyone for considering this.

At 03:41 AM 2/7/2021, you wrote:

>Dennis Sweeney  added the comment:
>
>I think the strangeness is happening because sometimes, the warning 
>is printed to stderr, while other times, IDLE's parser notices the 
>"is " anti-pattern and raises a SyntaxError.
>
>See the attached screenshot for the IDLE output versus the console 
>output for a recent 3.10 build.
>
>--
>Added file: https://bugs.python.org/file49796/idle_stderr.jpg
>
>___
>Python tracker 
>
>___

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43151] is with literals in 3.8 release

2021-02-07 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

I think the strangeness is happening because sometimes, the warning is printed 
to stderr, while other times, IDLE's parser notices the "is " 
anti-pattern and raises a SyntaxError.

See the attached screenshot for the IDLE output versus the console output for a 
recent 3.10 build.

--
Added file: https://bugs.python.org/file49796/idle_stderr.jpg

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43151] is with literals in 3.8 release

2021-02-07 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

There may be reason to re-open this.

With Python 3.9.0, I see the inconsistent behavior that Gary describes only 
when using IDLE. So this is likely an IDLE issue.

I attached a screenshot of the difference.

--
Added file: https://bugs.python.org/file49795/idle_vs_console.jpg

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43151] is with literals in 3.8 release

2021-02-06 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

Gary, I cannot replicate that inconsistency in 3.9.0.


>>> x = "abc"
>>> x is "abc"
:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
True
>>> if x is "abc": pass
... 
:1: SyntaxWarning: "is" with a literal. Did you mean "=="?


I don't believe that you should be getting a SyntaxError at all, and both cases 
should give the same warning. Can you double-check your code, and if you 
confirm that they give a different result or a SyntaxError, let us know here. 
Otherwise Raymond and Dennis are correct: this is working correctly.

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43151] is with literals in 3.8 release

2021-02-06 Thread Gary Litvin


Gary Litvin  added the comment:

Thank you for your responses. I understand the difference between == 
and "is" and the intentional change in 3.8. My question is about what 
seems to be inconsistent treatment in x is 'a' and if a is 'a': ...

At 12:49 AM 2/7/2021, Raymond Hettinger wrote:

>Raymond Hettinger  added the comment:
>
>As Dennis says, this is an intentional behavior and will help you avoid bugs.
>
>--
>nosy: +rhettinger
>resolution:  -> not a bug
>stage:  -> resolved
>status: open -> closed
>
>___
>Python tracker 
>
>___

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43151] is with literals in 3.8 release

2021-02-06 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

As Dennis says, this is an intentional behavior and will help you avoid bugs.

--
nosy: +rhettinger
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43151] is with literals in 3.8 release

2021-02-06 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

This was a very intentional change from the commit 
3bcbedc9f1471d957a30a90f9d1251516b422416

It's not safe to check `x is y` when x and y are strings.
You should always use `x == y` for strings instead.
In CPython, if the names x and y both refer to the same underlying object, then 
`x is y` will return True.
In CPython, if the names x and y refer to two distinct string objects with 
equal values, then `x is y` will return False.
Which case happens is an implementation detail, and alternate Python 
implementations like PyPy could behave unexpectedly with such code.
As such, to prevent more incorrect code, this was changed to emit a 
SyntaxWarning in Python 3.8.

This is documented here:
https://docs.python.org/3/whatsnew/3.8.html#changes-in-python-behavior

In a python REPL, I believe SyntaxWarnings are by default promoted to 
SyntaxErrors. But when running a file with `python -Wa`, you just get the 
warning:

$ python -Wa ./a.py
.../a.py:2: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if x is 'a':
a

--
nosy: +Dennis Sweeney

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43151] is with literals in 3.8 release

2021-02-06 Thread Gary Litvin


New submission from Gary Litvin :

>>> x = 'a'
>>> x is 'a'
True
>>> if x is 'a':
print(x)

SyntaxError: "is" with a literal. Did you mean "=="?

How come?

--
messages: 386575
nosy: garylitvin
priority: normal
severity: normal
status: open
title: is with literals in 3.8 release
versions: Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com