mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	bpo-42128: Add 'missing :' syntax error message to match statements (GH-24733)
This commit is contained in:
		
							parent
							
								
									526fdeb227
								
							
						
					
					
						commit
						08fb8ac99a
					
				
					 3 changed files with 368 additions and 184 deletions
				
			
		|  | @ -825,6 +825,24 @@ | |||
|    Traceback (most recent call last): | ||||
|    SyntaxError: expected ':' | ||||
| 
 | ||||
|    >>> match x | ||||
|    ...   case list(): | ||||
|    ...       pass | ||||
|    Traceback (most recent call last): | ||||
|    SyntaxError: expected ':' | ||||
| 
 | ||||
|    >>> match x: | ||||
|    ...   case list() | ||||
|    ...       pass | ||||
|    Traceback (most recent call last): | ||||
|    SyntaxError: expected ':' | ||||
| 
 | ||||
|    >>> match x: | ||||
|    ...   case [y] if y > 0 | ||||
|    ...       pass | ||||
|    Traceback (most recent call last): | ||||
|    SyntaxError: expected ':' | ||||
| 
 | ||||
| Make sure that the old "raise X, Y[, Z]" form is gone: | ||||
|    >>> raise X, Y | ||||
|    Traceback (most recent call last): | ||||
|  | @ -1159,6 +1177,24 @@ def test_error_parenthesis(self): | |||
|         for paren in ")]}": | ||||
|             self._check_error(paren + "1 + 2", f"unmatched '\\{paren}'") | ||||
| 
 | ||||
|     def test_match_call_does_not_raise_syntax_error(self): | ||||
|         code = """ | ||||
| def match(x): | ||||
|     return 1+1 | ||||
| 
 | ||||
| match(34) | ||||
| """ | ||||
|         compile(code, "<string>", "exec") | ||||
| 
 | ||||
|     def test_case_call_does_not_raise_syntax_error(self): | ||||
|         code = """ | ||||
| def case(x): | ||||
|     return 1+1 | ||||
| 
 | ||||
| case(34) | ||||
| """ | ||||
|         compile(code, "<string>", "exec") | ||||
| 
 | ||||
| 
 | ||||
| def test_main(): | ||||
|     support.run_unittest(SyntaxTestCase) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Pablo Galindo
						Pablo Galindo