Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ real_number[expr_ty]:

imaginary_number[expr_ty]:
| imag=NUMBER { _PyPegen_ensure_imaginary(p, imag) }
| '+' imag=NUMBER { _PyPegen_ensure_imaginary(p, imag) }

capture_pattern[pattern_ty]:
| target=pattern_capture_target { _PyAST_MatchAs(NULL, target->v.Name.id, EXTRA) }
Expand Down
36 changes: 28 additions & 8 deletions Lib/test/test_patma.py
Original file line number Diff line number Diff line change
Expand Up @@ -2835,14 +2835,6 @@ def test_patma_264(self):
self.assertEqual(y, 0)

def test_patma_265(self):
x = 0.25 - 1.75j
match x:
case 0.25 - +1.75j:
y = 0
self.assertEqual(x, 0.25 - 1.75j)
self.assertEqual(y, 0)

def test_patma_266(self):
x = 0
match x:
case +1e1000:
Expand Down Expand Up @@ -3329,6 +3321,34 @@ def test_mapping_pattern_duplicate_key_edge_case3(self):
pass
""")

def test_duplicate_sign_in_complex_1(self):
self.assert_syntax_error("""
match ...:
case 0 ++ 0j:
pass
""")

def test_duplicate_sign_in_complex_2(self):
self.assert_syntax_error("""
match ...:
case 0 -+ 0j:
pass
""")

def test_duplicate_sign_in_complex_3(self):
self.assert_syntax_error("""
match ...:
case 0 +- 0j:
pass
""")

def test_duplicate_sign_in_complex_4(self):
self.assert_syntax_error("""
match ...:
case 0 -- 0j:
pass
""")

class TestTypeErrors(unittest.TestCase):

def test_accepts_positional_subpatterns_0(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When matching a complex literal in :keyword:`case` statements, an extraneous
``+`` sign (for example, ``1++1j`` or ``1-+1j``) is no longer allowed.
29 changes: 1 addition & 28 deletions Parser/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading