mirror of https://github.com/python/cpython
gh-98931: Add custom error messages to invalid import/from with multiple targets (#105985)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
a8006706f7
commit
13237a2da8
|
@ -1293,7 +1293,7 @@ invalid_group:
|
||||||
| '(' a='**' expression ')' {
|
| '(' a='**' expression ')' {
|
||||||
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot use double starred expression here") }
|
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot use double starred expression here") }
|
||||||
invalid_import:
|
invalid_import:
|
||||||
| a='import' dotted_name 'from' dotted_name {
|
| a='import' ','.dotted_name+ 'from' dotted_name {
|
||||||
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "Did you mean to use 'from ... import ...' instead?") }
|
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "Did you mean to use 'from ... import ...' instead?") }
|
||||||
|
|
||||||
invalid_import_from_targets:
|
invalid_import_from_targets:
|
||||||
|
|
|
@ -1621,6 +1621,22 @@ SyntaxError: Did you mean to use 'from ... import ...' instead?
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
SyntaxError: Did you mean to use 'from ... import ...' instead?
|
SyntaxError: Did you mean to use 'from ... import ...' instead?
|
||||||
|
|
||||||
|
>>> import a, b,c from b
|
||||||
|
Traceback (most recent call last):
|
||||||
|
SyntaxError: Did you mean to use 'from ... import ...' instead?
|
||||||
|
|
||||||
|
>>> import a.y.z, b.y.z, c.y.z from b.y.z
|
||||||
|
Traceback (most recent call last):
|
||||||
|
SyntaxError: Did you mean to use 'from ... import ...' instead?
|
||||||
|
|
||||||
|
>>> import a,b,c from b as bar
|
||||||
|
Traceback (most recent call last):
|
||||||
|
SyntaxError: Did you mean to use 'from ... import ...' instead?
|
||||||
|
|
||||||
|
>>> import a.y.z, b.y.z, c.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
|
# Check that we dont raise the "trailing comma" error if there is more
|
||||||
# input to the left of the valid part that we parsed.
|
# input to the left of the valid part that we parsed.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Ensure custom :exc:`SyntaxError` error messages are raised for invalid
|
||||||
|
imports with multiple targets. Patch by Pablo Galindo
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue