summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2012-11-16 13:17:08 +0200
committerEzio Melotti <ezio.melotti@gmail.com>2012-11-16 13:17:08 +0200
commit103f17ef918188ea2f50b01bb616953082d5f4e2 (patch)
tree780094a7b499807afe5e5f509b740624b14a3916
parentb37ac8eaf610c82c792ed038508b959e1bff686e (diff)
downloadcpython-git-103f17ef918188ea2f50b01bb616953082d5f4e2.tar.gz
#16478: use floor division in tabnanny and fix a ResourceWarning. Patch by Serhiy Storchaka.
-rwxr-xr-xLib/tabnanny.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/Lib/tabnanny.py b/Lib/tabnanny.py
index 46f8163e5f..5b9b444c1a 100755
--- a/Lib/tabnanny.py
+++ b/Lib/tabnanny.py
@@ -126,6 +126,9 @@ def check(file):
else: print(file, badline, repr(line))
return
+ finally:
+ f.close()
+
if verbose:
print("%r: Clean bill of health." % (file,))
@@ -185,21 +188,21 @@ class Whitespace:
# count, il = self.norm
# for i in range(len(count)):
# if count[i]:
- # il = il + (i/tabsize + 1)*tabsize * count[i]
+ # il = il + (i//tabsize + 1)*tabsize * count[i]
# return il
# quicker:
- # il = trailing + sum (i/ts + 1)*ts*count[i] =
- # trailing + ts * sum (i/ts + 1)*count[i] =
- # trailing + ts * sum i/ts*count[i] + count[i] =
- # trailing + ts * [(sum i/ts*count[i]) + (sum count[i])] =
- # trailing + ts * [(sum i/ts*count[i]) + num_tabs]
- # and note that i/ts*count[i] is 0 when i < ts
+ # il = trailing + sum (i//ts + 1)*ts*count[i] =
+ # trailing + ts * sum (i//ts + 1)*count[i] =
+ # trailing + ts * sum i//ts*count[i] + count[i] =
+ # trailing + ts * [(sum i//ts*count[i]) + (sum count[i])] =
+ # trailing + ts * [(sum i//ts*count[i]) + num_tabs]
+ # and note that i//ts*count[i] is 0 when i < ts
count, trailing = self.norm
il = 0
for i in range(tabsize, len(count)):
- il = il + i/tabsize * count[i]
+ il = il + i//tabsize * count[i]
return trailing + tabsize * (il + self.nt)
# return true iff self.indent_level(t) == other.indent_level(t)