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.

classification
Title: Bug or plug not removed (The operator "is")
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Dennis Sweeney, JelleZijlstra, eric.smith, rhettinger, semina054
Priority: normal Keywords:

Created on 2022-03-07 00:42 by semina054, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
изображение_2022-03-07_023751.png semina054, 2022-03-07 00:42
Messages (5)
msg414630 - (view) Author: Роман Слабицкий (semina054) Date: 2022-03-07 00:42
I understand it's a stub that hasn't been removed, so it's a message from the C language that Python runs on in principle.
msg414632 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-03-07 01:02
I don't understand what you are referring to. What do you think is wrong?
msg414633 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-03-07 01:08
In the future, please copy and paste the relevant code and errors as text. Images of code are harder for screen-readers for the visually impaired, harder to copy-and-paste to verify, and are more likely to be perceived as spam.

Your code is essentially this:

>>> i = 0
>>> i is 0
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
True

This warning isn't a "stub", it was intentionally added in GH-9642. The warning exists because comparing numbers with `is` is generally unsafe (numbers should be compared using `==` instead), and can lead to unpredictable results, especially if using a different Python implementation (e.g. PyPy or RustPython or Jython rather than CPython).
msg414634 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2022-03-07 01:21
The code in the screenshot looks correct.



>>> i = 0
>>> i is int    
False
>>> type(i) is int
True

The code above does not get warning because "int" is a variable.  This kind of comparison is always allowed and will work reliably.



>>> i is 0
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
True

The above code generates a warning because 0 is a numeric literal and there may be more than one instance of that literal.  While this kind of comparison is allowed, it is unreliable because numeric literals are not guaranteed to be singletons:

    >>> x = 600
    >>> (x + x) is 1200
    <stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
    False



The reliable and correct way to test numeric values with an equality:

    >>> x + x == 1200
    True
msg414635 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-03-07 02:32
As others have noted, the behavior is intentional, so I'm closing this.
History
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91097
2022-03-07 02:32:18eric.smithsetstatus: open -> closed

nosy: + Dennis Sweeney, eric.smith, JelleZijlstra
messages: + msg414635

resolution: not a bug
stage: resolved
2022-03-07 01:21:16rhettingersetnosy: + rhettinger, - JelleZijlstra, Dennis Sweeney
messages: + msg414634
2022-03-07 01:08:02Dennis Sweeneysetnosy: + Dennis Sweeney
messages: + msg414633
2022-03-07 01:02:45JelleZijlstrasetnosy: + JelleZijlstra
messages: + msg414632
2022-03-07 00:42:57semina054create