MCPcopy Index your code
hub / github.com/python/cpython / test_parser_deeply_nested_patterns

Method test_parser_deeply_nested_patterns

Lib/test/test_patma.py:3503–3522  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3501
3502 @support.skip_wasi_stack_overflow()
3503 def test_parser_deeply_nested_patterns(self):
3504 # Deeply nested patterns can cause exponential backtracking when parsing.
3505 # See gh-93671 for more information.
3506
3507 levels = 100
3508
3509 patterns = [
3510 "A" + "(" * levels + ")" * levels,
3511 "{1:" * levels + "1" + "}" * levels,
3512 "[" * levels + "1" + "]" * levels,
3513 ]
3514
3515 for pattern in patterns:
3516 with self.subTest(pattern):
3517 code = inspect.cleandoc("""
3518 match None:
3519 case {}:
3520 pass
3521 """.format(pattern))
3522 compile(code, "<string>", "exec")
3523
3524
3525if __name__ == "__main__":

Callers

nothing calls this directly

Calls 3

compileFunction · 0.50
subTestMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected