Skip to content

Commit d40b6c5

Browse files
committed
Fix autopatching at the start of a file
1 parent 3190a51 commit d40b6c5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

graalpython/lib-graalpython/modules/autopatch_capi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def replace_field_access(contents, match, replacement, assignment):
6666
level = 0
6767

6868
def consume_whitespace_backwards(idx):
69-
while idx > 0 and contents[idx].isspace():
69+
while idx >= 0 and contents[idx].isspace():
7070
idx -= 1
7171
return idx
7272

@@ -85,7 +85,7 @@ def consume_whitespace_forward(idx):
8585
def consume_pairwise_backwards(idx, l, r):
8686
level = 1
8787
idx -= 1
88-
while level and idx:
88+
while level and idx >= 0:
8989
c = contents[idx]
9090
if c == l:
9191
level -= 1
@@ -95,12 +95,12 @@ def consume_pairwise_backwards(idx, l, r):
9595
return idx
9696

9797
def consume_identifier_backwards(idx):
98-
while (contents[idx].isidentifier() or contents[idx].isdigit()) and idx:
98+
while idx >= 0 and (contents[idx].isidentifier() or contents[idx].isdigit()):
9999
idx -= 1
100100
return idx
101101

102102
first = True
103-
while idx:
103+
while idx >= 0:
104104
c = contents[idx]
105105
if c == ')' and first:
106106
idx = consume_pairwise_backwards(idx, '(', ')')

0 commit comments

Comments
 (0)