mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
gh-123539: Improve SyntaxError msg for import as with not a name (#123629)
This commit is contained in:
parent
39afd290ae
commit
a6ddd078d0
4 changed files with 1309 additions and 982 deletions
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue