Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 103f17e

Browse files
committed
#16478: use floor division in tabnanny and fix a ResourceWarning. Patch by Serhiy Storchaka.
1 parent b37ac8e commit 103f17e

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

Lib/tabnanny.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ def check(file):
126126
else: print(file, badline, repr(line))
127127
return
128128

129+
finally:
130+
f.close()
131+
129132
if verbose:
130133
print("%r: Clean bill of health." % (file,))
131134

@@ -185,21 +188,21 @@ def indent_level(self, tabsize):
185188
# count, il = self.norm
186189
# for i in range(len(count)):
187190
# if count[i]:
188-
# il = il + (i/tabsize + 1)*tabsize * count[i]
191+
# il = il + (i//tabsize + 1)*tabsize * count[i]
189192
# return il
190193

191194
# quicker:
192-
# il = trailing + sum (i/ts + 1)*ts*count[i] =
193-
# trailing + ts * sum (i/ts + 1)*count[i] =
194-
# trailing + ts * sum i/ts*count[i] + count[i] =
195-
# trailing + ts * [(sum i/ts*count[i]) + (sum count[i])] =
196-
# trailing + ts * [(sum i/ts*count[i]) + num_tabs]
197-
# and note that i/ts*count[i] is 0 when i < ts
195+
# il = trailing + sum (i//ts + 1)*ts*count[i] =
196+
# trailing + ts * sum (i//ts + 1)*count[i] =
197+
# trailing + ts * sum i//ts*count[i] + count[i] =
198+
# trailing + ts * [(sum i//ts*count[i]) + (sum count[i])] =
199+
# trailing + ts * [(sum i//ts*count[i]) + num_tabs]
200+
# and note that i//ts*count[i] is 0 when i < ts
198201

199202
count, trailing = self.norm
200203
il = 0
201204
for i in range(tabsize, len(count)):
202-
il = il + i/tabsize * count[i]
205+
il = il + i//tabsize * count[i]
203206
return trailing + tabsize * (il + self.nt)
204207

205208
# return true iff self.indent_level(t) == other.indent_level(t)

0 commit comments

Comments
 (0)