@@ -468,9 +468,12 @@ def _parse_from_import_source(self):
468
468
self .stream .move ()
469
469
is_future_import = self .current .value == '__future__'
470
470
self .stream .move ()
471
- while (self .current .kind in (tk .DOT , tk .NAME , tk .OP ) and
472
- self .current .value != 'import' ):
471
+ while (self .current is not None and
472
+ self .current .kind in (tk .DOT , tk .NAME , tk .OP ) and
473
+ self .current .value != 'import' ):
473
474
self .stream .move ()
475
+ if self .current is None or self .current .value != 'import' :
476
+ return False
474
477
self .check_current (value = 'import' )
475
478
assert self .current .value == 'import' , self .current .value
476
479
self .stream .move ()
@@ -480,10 +483,10 @@ def _parse_from_import_names(self, is_future_import):
480
483
"""Parse the 'y' part in a 'from x import y' statement."""
481
484
if self .current .value == '(' :
482
485
self .consume (tk .OP )
483
- expected_end_kind = tk .OP
486
+ expected_end_kinds = ( tk .OP , )
484
487
else :
485
- expected_end_kind = tk .NEWLINE
486
- while self .current .kind != expected_end_kind and not (
488
+ expected_end_kinds = ( tk .NEWLINE , tk . ENDMARKER )
489
+ while self .current .kind not in expected_end_kinds and not (
487
490
self .current .kind == tk .OP and self .current .value == ';' ):
488
491
if self .current .kind != tk .NAME :
489
492
self .stream .move ()
@@ -504,4 +507,3 @@ def _parse_from_import_names(self, is_future_import):
504
507
self .consume (tk .OP )
505
508
self .log .debug ("parsing import, token is %r (%s)" ,
506
509
self .current .kind , self .current .value )
507
-
0 commit comments