gh-98931: Improve error message when the user types 'import x from y' instead of 'from y import x' (#98932)

This commit is contained in:
Pablo Galindo Salgado 2022-11-01 13:01:20 +00:00 committed by GitHub
parent 0e15c31c7e
commit 395d4285bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 503 additions and 392 deletions

View file

@ -1584,6 +1584,22 @@ SyntaxError: trailing comma not allowed without surrounding parentheses
Traceback (most recent call last):
SyntaxError: trailing comma not allowed without surrounding parentheses
>>> import a from b
Traceback (most recent call last):
SyntaxError: Did you mean to use 'from ... import ...' instead?
>>> import a.y.z from b.y.z
Traceback (most recent call last):
SyntaxError: Did you mean to use 'from ... import ...' instead?
>>> import a from b as bar
Traceback (most recent call last):
SyntaxError: Did you mean to use 'from ... import ...' instead?
>>> import a.y.z from b.y.z as bar
Traceback (most recent call last):
SyntaxError: Did you mean to use 'from ... import ...' instead?
# Check that we dont raise the "trailing comma" error if there is more
# input to the left of the valid part that we parsed.