summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2022-07-17 11:18:06 +0100
committerda-woods <dw-git@d-woods.co.uk>2022-07-17 11:18:06 +0100
commit9924b689f3f6160f48dbf7a17df0f0b9f277f583 (patch)
treed524a441a67a40f908de3a794a56852020c5b44d
parentb1ffd71c4af5888173fda64b2bca43f709b6893a (diff)
downloadcython-9924b689f3f6160f48dbf7a17df0f0b9f277f583.tar.gz
Updated test_patma to match most recent CPython
-rw-r--r--tests/run/test_patma.py48
1 files changed, 46 insertions, 2 deletions
diff --git a/tests/run/test_patma.py b/tests/run/test_patma.py
index 690cb9086..d815b7191 100644
--- a/tests/run/test_patma.py
+++ b/tests/run/test_patma.py
@@ -1,4 +1,4 @@
-### COPIED FROM CPython 3.9
+### COPIED FROM CPython 3.12 alpha (July 2022)
### Original part after ############
# cython: language_level=3
@@ -61,7 +61,36 @@ else:
y: int
# TestCompiler removed - it's very CPython-specific
-# TestTracing also removed - doesn't seem like a core test
+# TestTracing also mainly removed - doesn't seem like a core test
+# except for one test that seems misplaced in CPython (which is below)
+
+class TestTracing(unittest.TestCase):
+ def test_parser_deeply_nested_patterns(self):
+ # Deeply nested patterns can cause exponential backtracking when parsing.
+ # See CPython gh-93671 for more information.
+ #
+ # DW Cython note - this doesn't break the parser but may cause a
+ # RecursionError later in the code-generation. I don't believe that's
+ # easily avoidable
+
+ levels = 100
+
+ patterns = [
+ "A" + "(" * levels + ")" * levels,
+ "{1:" * levels + "1" + "}" * levels,
+ "[" * levels + "1" + "]" * levels,
+ ]
+
+ for pattern in patterns:
+ with self.subTest(pattern):
+ code = inspect.cleandoc("""
+ if 0: # FIXME remove once pattern matching is fully implemented!
+ match None:
+ case {}:
+ pass
+ """.format(pattern))
+ compile(code, "<string>", "exec")
+
# FIXME - remove all the "return"s added to cause code to be dropped
############## ORIGINAL PART FROM CPYTHON
@@ -2953,6 +2982,21 @@ class TestPatma(unittest.TestCase):
self.assertEqual(y, 'bar')
+ def test_patma_249(self):
+ return
+ class C:
+ __attr = "eggs" # mangled to _C__attr
+ _Outer__attr = "bacon"
+ class Outer:
+ def f(self, x):
+ match x:
+ # looks up __attr, not _C__attr or _Outer__attr
+ case C(__attr=y):
+ return y
+ c = C()
+ setattr(c, "__attr", "spam") # setattr is needed because we're in a class scope
+ self.assertEqual(Outer().f(c), "spam")
+
class TestSyntaxErrors(unittest.TestCase):