Skip to content

Commit 243e173

Browse files
committed
Fix parsing relative imports with '...' tokens
Fixed #585.
1 parent e3259f3 commit 243e173

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

mypy/parse.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ def parse_import_from(self) -> Node:
164164

165165
# Build the list of beginning relative tokens.
166166
relative = 0
167-
while self.current_str() == ".":
168-
self.expect('.')
169-
relative += 1
167+
while self.current_str() in (".", "..."):
168+
relative += len(self.current_str())
169+
self.skip()
170170

171171
# Parse qualified name to actually import from.
172172
if self.current_str() == "import":

mypy/test/data/parse.test

+12
Original file line numberDiff line numberDiff line change
@@ -3169,3 +3169,15 @@ MypyFile:1(
31693169
z))
31703170
Block:1(
31713171
PassStmt:1())))
3172+
3173+
[case testRelativeImportWithEllipsis]
3174+
from ... import x
3175+
[out]
3176+
MypyFile:1(
3177+
ImportFrom:1(..., [x : x]))
3178+
3179+
[case testRelativeImportWithEllipsis2]
3180+
from .... import x
3181+
[out]
3182+
MypyFile:1(
3183+
ImportFrom:1(...., [x : x]))

0 commit comments

Comments
 (0)