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: duplicate SyntaxWarning: "is" with a literal
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: jwilk, kakshay, serhiy.storchaka, terry.reedy, vstinner
Priority: normal Keywords: patch, patch, patch

Created on 2019-01-21 15:13 by jwilk, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11639 merged serhiy.storchaka, 2019-01-21 19:06
PR 11639 merged serhiy.storchaka, 2019-01-21 19:06
PR 11639 merged serhiy.storchaka, 2019-01-21 19:06
PR 11642 closed kakshay, 2019-01-21 21:14
PR 11642 closed kakshay, 2019-01-21 21:14
PR 11642 closed kakshay, 2019-01-21 21:14
PR 11895 merged serhiy.storchaka, 2019-02-16 13:26
Messages (7)
msg334143 - (view) Author: Jakub Wilk (jwilk) Date: 2019-01-21 15:13
$ python3.8 -c 'if object() is 42: pass'
<string>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
<string>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?

I'd like only one copy of this warning, not two.

Tested with git master (e9b185f2a493cc54f0d49eac44bf21e8d7de2990).
msg334144 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-21 15:18
The warning has been introduced by bpo-34850: commit 3bcbedc9f1471d957a30a90f9d1251516b422416.
msg334169 - (view) Author: Kumar Akshay (kakshay) * Date: 2019-01-21 19:41
can I work on this?
msg334366 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-01-25 20:35
I verified that master on Windows (which requires " instead of ')
> python -c "if object() is 42: pass"
results in the doubled messsage, and that after applying PR 11639 and recompiling, there is only 1 message.

We should test that exactly 1 warning is emitted.  The following fails on master and passes with the parch:

import unittest, warnings

class SyntaxWarningTest(unittest.TestCase):
    def test_syntax_warning_once(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            compile('if object() is 42: pass\n', '', 'single')
            self.assertEqual(len(w), 1)  # Not 2, see issue 35798

if __name__ == '__main__':
    unittest.main()
    
The original patch added test_comparison_is_literal() in test_grammar.  The 'with' block above could be added at the end.
msg335670 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-02-16 06:29
This warning is not special. I'll add a helper for testing that all syntax warnings are emitted only once later.
msg335671 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-02-16 06:29
New changeset 4583525835baf8fc7bd49a60725d1e8c49ef92b3 by Serhiy Storchaka in branch 'master':
bpo-35798: Fix duplicate SyntaxWarning: "is" with a literal. (GH-11639)
https://github.com/python/cpython/commit/4583525835baf8fc7bd49a60725d1e8c49ef92b3
msg335891 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-02-19 06:30
New changeset e7a4bb554edb72fc6619d23241d59162d06f249a by Serhiy Storchaka in branch 'master':
bpo-35798: Add test.support.check_syntax_warning(). (#11895)
https://github.com/python/cpython/commit/e7a4bb554edb72fc6619d23241d59162d06f249a
History
Date User Action Args
2022-04-11 14:59:10adminsetgithub: 79979
2019-02-19 06:48:16serhiy.storchakasetkeywords: patch, patch, patch
status: pending -> closed
2019-02-19 06:48:00serhiy.storchakasetkeywords: patch, patch, patch
status: open -> pending
resolution: fixed
stage: patch review -> resolved
2019-02-19 06:30:19serhiy.storchakasetmessages: + msg335891
2019-02-16 13:26:06serhiy.storchakasetpull_requests: + pull_request11922
2019-02-16 06:29:48serhiy.storchakasetmessages: + msg335671
2019-02-16 06:29:30serhiy.storchakasetkeywords: patch, patch, patch

messages: + msg335670
2019-01-25 20:35:08terry.reedysetkeywords: patch, patch, patch
nosy: + terry.reedy
messages: + msg334366

2019-01-21 21:14:21kakshaysetpull_requests: + pull_request11421
2019-01-21 21:14:13kakshaysetpull_requests: + pull_request11420
2019-01-21 21:14:04kakshaysetpull_requests: + pull_request11419
2019-01-21 19:41:38kakshaysetnosy: + kakshay
messages: + msg334169
2019-01-21 19:06:34serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request11412
2019-01-21 19:06:29serhiy.storchakasetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11411
2019-01-21 19:06:24serhiy.storchakasetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11410
2019-01-21 15:18:50vstinnersetnosy: + vstinner
messages: + msg334144
2019-01-21 15:13:45jwilkcreate