mirror of
https://github.com/python/cpython.git
synced 2025-10-26 03:04:41 +00:00
gh-136616: Improve assert syntax error messages (#136653)
This commit is contained in:
parent
66ef16105a
commit
6bc65c30ff
4 changed files with 594 additions and 400 deletions
|
|
@ -2686,6 +2686,71 @@ def f(x: *b)
|
|||
>>> f(x = 5, *:)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Invalid star expression
|
||||
|
||||
Asserts:
|
||||
|
||||
>>> assert (a := 1) # ok
|
||||
>>> # TODO(@sobolevn): improve this message in the next PR
|
||||
>>> assert a := 1
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: invalid syntax
|
||||
|
||||
>>> assert 1 = 2 = 3
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
|
||||
|
||||
>>> assert 1 = 2
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
|
||||
|
||||
>>> assert (1 = 2)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
|
||||
|
||||
>>> assert 'a' = a
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
|
||||
|
||||
>>> assert x[0] = 1
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot assign to subscript here. Maybe you meant '==' instead of '='?
|
||||
|
||||
>>> assert (yield a) = 2
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot assign to yield expression here. Maybe you meant '==' instead of '='?
|
||||
|
||||
>>> assert a = 2
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot assign to name here. Maybe you meant '==' instead of '='?
|
||||
|
||||
>>> assert (a = 2)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
|
||||
|
||||
>>> assert a = b
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot assign to name here. Maybe you meant '==' instead of '='?
|
||||
|
||||
>>> assert 1, 1 = b
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
|
||||
|
||||
>>> assert 1, (1 = b)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
|
||||
|
||||
>>> assert 1, a = 1
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot assign to name here. Maybe you meant '==' instead of '='?
|
||||
|
||||
>>> assert 1, (a = 1)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
|
||||
|
||||
>>> assert 1 = a, a = 1
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
|
||||
|
||||
"""
|
||||
|
||||
import re
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue