mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-138857: Improve error message for case outside of match (#138858)
* gh-138857: Improve error message for `case` outside of `match` --------- Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
This commit is contained in:
parent
161b3064ef
commit
92c0c45563
4 changed files with 80 additions and 0 deletions
|
|
@ -376,6 +376,42 @@
|
|||
Traceback (most recent call last):
|
||||
SyntaxError: invalid syntax
|
||||
|
||||
# Check incorrect "case" placement with specialized error messages
|
||||
|
||||
>>> case "pattern": ...
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: case statement must be inside match statement
|
||||
|
||||
>>> case 1 | 2: ...
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: case statement must be inside match statement
|
||||
|
||||
>>> case klass(attr=1) | {}: ...
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: case statement must be inside match statement
|
||||
|
||||
>>> case [] if x > 1: ...
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: case statement must be inside match statement
|
||||
|
||||
>>> case match: ...
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: case statement must be inside match statement
|
||||
|
||||
>>> case case: ...
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: case statement must be inside match statement
|
||||
|
||||
>>> if some:
|
||||
... case 1: ...
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: case statement must be inside match statement
|
||||
|
||||
>>> case some:
|
||||
... case 1: ...
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: case statement must be inside match statement
|
||||
|
||||
# But prefixes of soft keywords should
|
||||
# still raise specialized errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue