[issue35798] duplicate SyntaxWarning: "is" with a literal
Terry J. Reedy
report at bugs.python.org
Fri Jan 25 15:35:08 EST 2019
Terry J. Reedy <tjreedy at udel.edu> added the comment:
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.
----------
nosy: +terry.reedy
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35798>
_______________________________________
More information about the Python-bugs-list
mailing list