gh-123539: Improve SyntaxError msg for import as with not a name (#123629)

This commit is contained in:
sobolevn 2025-05-02 11:34:13 +03:00 committed by GitHub
parent 39afd290ae
commit a6ddd078d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 1309 additions and 982 deletions

View file

@ -1981,6 +1981,56 @@ SyntaxError: cannot assign to __debug__
Traceback (most recent call last):
SyntaxError: cannot assign to __debug__
>>> import a as b.c
Traceback (most recent call last):
SyntaxError: cannot use attribute as import target
>>> import a.b as (a, b)
Traceback (most recent call last):
SyntaxError: cannot use tuple as import target
>>> import a, a.b as 1
Traceback (most recent call last):
SyntaxError: cannot use literal as import target
>>> import a.b as 'a', a
Traceback (most recent call last):
SyntaxError: cannot use literal as import target
>>> from a import (b as c.d)
Traceback (most recent call last):
SyntaxError: cannot use attribute as import target
>>> from a import b as 1
Traceback (most recent call last):
SyntaxError: cannot use literal as import target
>>> from a import (
... b as f())
Traceback (most recent call last):
SyntaxError: cannot use function call as import target
>>> from a import (
... b as [],
... )
Traceback (most recent call last):
SyntaxError: cannot use list as import target
>>> from a import (
... b,
... c as ()
... )
Traceback (most recent call last):
SyntaxError: cannot use tuple as import target
>>> from a import b, с as d[e]
Traceback (most recent call last):
SyntaxError: cannot use subscript as import target
>>> from a import с as d[e], b
Traceback (most recent call last):
SyntaxError: cannot use subscript as import target
# Check that we dont raise the "trailing comma" error if there is more
# input to the left of the valid part that we parsed.