mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
bpo-24612: Improve syntax error for 'not' after an operator (GH-28170)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
This commit is contained in:
parent
771902c257
commit
61599a48f5
4 changed files with 1392 additions and 964 deletions
|
@ -1712,6 +1712,49 @@ SyntaxError: only single target (not tuple) can be annotated
|
|||
Traceback (most recent call last):
|
||||
SyntaxError: only single target (not list) can be annotated
|
||||
|
||||
# 'not' after operators:
|
||||
|
||||
>>> 3 + not 3
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: 'not' after an operator must be parenthesized
|
||||
|
||||
>>> 3 * not 3
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: 'not' after an operator must be parenthesized
|
||||
|
||||
>>> + not 3
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: 'not' after an operator must be parenthesized
|
||||
|
||||
>>> - not 3
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: 'not' after an operator must be parenthesized
|
||||
|
||||
>>> ~ not 3
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: 'not' after an operator must be parenthesized
|
||||
|
||||
>>> 3 + - not 3
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: 'not' after an operator must be parenthesized
|
||||
|
||||
>>> 3 + not -1
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: 'not' after an operator must be parenthesized
|
||||
|
||||
# Check that we don't introduce misleading errors
|
||||
>>> not 1 */ 2
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: invalid syntax
|
||||
|
||||
>>> not 1 +
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: invalid syntax
|
||||
|
||||
>>> not + 1 +
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: invalid syntax
|
||||
|
||||
Corner-cases that used to fail to raise the correct error:
|
||||
|
||||
>>> def f(*, x=lambda __debug__:0): pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue