gh-138944: Fix SyntaxError message for invalid syntax following valid import-as statement (#138945)

This commit is contained in:
Brian Schubert 2025-10-26 18:35:21 -04:00 committed by GitHub
parent 9d34623eb1
commit 3dab11f888
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 60 additions and 19 deletions

View file

@ -2163,6 +2163,25 @@
Traceback (most recent call last):
SyntaxError: cannot use subscript as import target
# Check that we don't raise a "cannot use name as import target" error
# if there is an error in an unrelated statement after ';'
>>> import a as b; None = 1
Traceback (most recent call last):
SyntaxError: cannot assign to None
>>> import a, b as c; d = 1; None = 1
Traceback (most recent call last):
SyntaxError: cannot assign to None
>>> from a import b as c; None = 1
Traceback (most recent call last):
SyntaxError: cannot assign to None
>>> from a import b, c as d; e = 1; None = 1
Traceback (most recent call last):
SyntaxError: cannot assign to None
# Check that we dont raise the "trailing comma" error if there is more
# input to the left of the valid part that we parsed.