summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2020-01-05 17:03:56 (GMT)
committerPablo Galindo <Pablogsal@gmail.com>2020-01-05 17:03:56 (GMT)
commitb121a4a45ff4bab8812a9b26ceffe5ad642f5d5a (patch)
treebb93879df6053614cb012368a1879d5cd96b4e72 /Lib
parent5ea7bb25e3b192d6c49a49c9e3b316f8559602aa (diff)
downloadcpython-b121a4a45ff4bab8812a9b26ceffe5ad642f5d5a.zip
cpython-b121a4a45ff4bab8812a9b26ceffe5ad642f5d5a.tar.gz
cpython-b121a4a45ff4bab8812a9b26ceffe5ad642f5d5a.tar.bz2
Fix constant folding optimization for positional only arguments (GH-17837)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_positional_only_arg.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_positional_only_arg.py b/Lib/test/test_positional_only_arg.py
index 63dee7c..2ef40e3 100644
--- a/Lib/test/test_positional_only_arg.py
+++ b/Lib/test/test_positional_only_arg.py
@@ -1,5 +1,6 @@
"""Unit tests for the positional only argument syntax specified in PEP 570."""
+import dis
import pickle
import unittest
@@ -419,6 +420,17 @@ class PositionalOnlyTestCase(unittest.TestCase):
def test_annotations(self):
assert global_inner_has_pos_only().__annotations__ == {'x': int}
+ def test_annotations_constant_fold(self):
+ def g():
+ def f(x: not (int is int), /): ...
+
+ # without constant folding we end up with
+ # COMPARE_OP(is), UNARY_NOT
+ # with constant folding we should expect a COMPARE_OP(is not)
+ codes = [(i.opname, i.argval) for i in dis.get_instructions(g)]
+ self.assertNotIn(('UNARY_NOT', None), codes)
+ self.assertIn(('COMPARE_OP', 'is not'), codes)
+
if __name__ == "__main__":
unittest.main()