Skip to content

Commit e42c7b6

Browse files
committed
test_is_import_statement: fix lazy imports
1 parent 85c434b commit e42c7b6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

rope/base/worder.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ def __init__(self, code, raw):
136136
self.code = code
137137
self.raw = raw
138138

139+
def _find_next_word_start(self, offset):
140+
current_offset = offset
141+
142+
try:
143+
end = self.code.index("\n", offset + 1)
144+
except ValueError:
145+
end = len(self.code)
146+
147+
while current_offset < end and not self._is_id_char(current_offset):
148+
current_offset += 1
149+
return current_offset
150+
139151
def _find_word_start(self, offset):
140152
current_offset = offset
141153
while current_offset >= 0 and self._is_id_char(current_offset):
@@ -341,7 +353,7 @@ def is_import_statement(self, offset):
341353
line_start = self._get_line_start(last_import)
342354
return (
343355
self._find_import_end(last_import + 7) >= offset
344-
and self._find_word_start(line_start) == last_import
356+
and self._find_next_word_start(line_start) == last_import
345357
)
346358

347359
def is_from_statement(self, offset):

0 commit comments

Comments
 (0)