|
2225 | 2225 | Traceback (most recent call last): |
2226 | 2226 | SyntaxError: Expected one or more names after 'import' |
2227 | 2227 |
|
| 2228 | +# Missing comma between import clauses |
| 2229 | +
|
2228 | 2230 | >>> import a b |
2229 | 2231 | Traceback (most recent call last): |
2230 | 2232 | SyntaxError: expected comma between import clauses |
2231 | 2233 |
|
| 2234 | +>>> import a, b c |
| 2235 | +Traceback (most recent call last): |
| 2236 | +SyntaxError: expected comma between import clauses |
| 2237 | +
|
2232 | 2238 | >>> import a.a as a b.b |
2233 | 2239 | Traceback (most recent call last): |
2234 | 2240 | SyntaxError: expected comma between import clauses |
2235 | 2241 |
|
| 2242 | +>>> import a.a as a b.b as b |
| 2243 | +Traceback (most recent call last): |
| 2244 | +SyntaxError: expected comma between import clauses |
| 2245 | +
|
2236 | 2246 | >>> from x import a b |
2237 | 2247 | Traceback (most recent call last): |
2238 | 2248 | SyntaxError: expected comma between import clauses |
|
2241 | 2251 | Traceback (most recent call last): |
2242 | 2252 | SyntaxError: expected comma between import clauses |
2243 | 2253 |
|
| 2254 | +>>> from x import (a |
| 2255 | +... b) |
| 2256 | +Traceback (most recent call last): |
| 2257 | +SyntaxError: expected comma between import clauses |
| 2258 | +
|
| 2259 | +>>> from x import (a as a |
| 2260 | +... b) |
| 2261 | +Traceback (most recent call last): |
| 2262 | +SyntaxError: expected comma between import clauses |
| 2263 | +
|
| 2264 | +>>> from x import (a, |
| 2265 | +... b as b |
| 2266 | +... c) |
| 2267 | +Traceback (most recent call last): |
| 2268 | +SyntaxError: expected comma between import clauses |
| 2269 | +
|
2244 | 2270 | >>> (): int |
2245 | 2271 | Traceback (most recent call last): |
2246 | 2272 | SyntaxError: only single target (not tuple) can be annotated |
@@ -3521,6 +3547,40 @@ def test_ifexp_body_stmt_else_stmt(self): |
3521 | 3547 | ]: |
3522 | 3548 | self._check_error(f"x = {lhs_stmt} if 1 else {rhs_stmt}", msg) |
3523 | 3549 |
|
| 3550 | + def test_import_missing_comma(self): |
| 3551 | + self._check_error("import a.a b.b", |
| 3552 | + "expected comma between import clauses", |
| 3553 | + offset=8, end_offset=8 + len("a.a b.b")) |
| 3554 | + self._check_error( |
| 3555 | + """if 1: |
| 3556 | + from x import ( |
| 3557 | + a, |
| 3558 | + b |
| 3559 | + c, |
| 3560 | + ) |
| 3561 | + """, |
| 3562 | + errtext="expected comma between import clauses", |
| 3563 | + lineno=4, |
| 3564 | + end_lineno=5, |
| 3565 | + offset=17, |
| 3566 | + end_offset=18, |
| 3567 | + ) |
| 3568 | + self._check_error( |
| 3569 | + """if 1: |
| 3570 | + from x import ( |
| 3571 | + a, |
| 3572 | + b as b |
| 3573 | + c as c, |
| 3574 | + ) |
| 3575 | + """, |
| 3576 | + errtext="expected comma between import clauses", |
| 3577 | + lineno=4, |
| 3578 | + end_lineno=5, |
| 3579 | + offset=22, |
| 3580 | + end_offset=18, |
| 3581 | + ) |
| 3582 | + |
| 3583 | + |
3524 | 3584 |
|
3525 | 3585 | class LazyImportRestrictionTestCase(SyntaxErrorTestCase): |
3526 | 3586 | """Test syntax restrictions for lazy imports.""" |
|
0 commit comments