Skip to content

Commit 203492e

Browse files
committed
Python 3 preparation: use // and __truediv__ as needed.
Tool-assisted patch. Those divisions that I thought must be integer floor divisions and rely on Python 2 integer floor division semantics are changed to use // (if any are actually meant to be floating-point divisions, that would break things). One __div__ method is changed to __truediv__ (with __div__ = __truediv__ for Python 2 compatibility).
1 parent 8f35136 commit 203492e

File tree

7 files changed

+27
-25
lines changed

7 files changed

+27
-25
lines changed

roundup/backends/blobfiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def subdirFilename(self, classname, nodeid, property=None):
221221
name = '%s%s'%(classname, nodeid)
222222

223223
# have a separate subdir for every thousand messages
224-
subdir = str(int(nodeid) / 1000)
224+
subdir = str(int(nodeid) // 1000)
225225
return os.path.join(subdir, name)
226226

227227
def _tempfile(self, filename):

roundup/cgi/TAL/TALInterpreter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def do_startTag(self, name_attrList,
277277
col = self.col + _len(name) + 1
278278
wrap = self.wrap
279279
align = col + 1
280-
if align >= wrap/2:
280+
if align >= wrap//2:
281281
align = 4 # Avoid a narrow column far to the right
282282
attrAction = self.dispatch["<attrAction>"]
283283
try:

roundup/date.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,9 @@ def dateDelta(self, other):
564564
sign = -1
565565
diff = -diff
566566
S = diff%60
567-
M = (diff/60)%60
568-
H = (diff/(60*60))%24
569-
d = diff/(24*60*60)
567+
M = (diff//60)%60
568+
H = (diff//(60*60))%24
569+
d = diff//(24*60*60)
570570
return Interval((0, 0, d, H, M, S), sign=sign,
571571
translator=self.translator)
572572

@@ -895,7 +895,7 @@ def __sub__(self, other):
895895
# nope, no idea what to do with this other...
896896
raise TypeError("Can't add %r"%other)
897897

898-
def __div__(self, other):
898+
def __truediv__(self, other):
899899
""" Divide this interval by an int value.
900900
901901
Can't divide years and months sensibly in the _same_
@@ -918,7 +918,7 @@ def __div__(self, other):
918918

919919
sign = months<0 and -1 or 1
920920
m = months%12
921-
y = months / 12
921+
y = months // 12
922922
return Interval((sign, y, m, 0, 0, 0, 0),
923923
translator=self.translator)
924924

@@ -932,21 +932,23 @@ def __div__(self, other):
932932
sign = seconds<0 and -1 or 1
933933
seconds *= sign
934934
S = seconds%60
935-
seconds /= 60
935+
seconds //= 60
936936
M = seconds%60
937-
seconds /= 60
937+
seconds //= 60
938938
H = seconds%24
939-
d = seconds / 24
939+
d = seconds // 24
940940
return Interval((sign, 0, 0, d, H, M, S),
941941
translator=self.translator)
942+
# Python 2 compatibility:
943+
__div__ = __truediv__
942944

943945
def __repr__(self):
944946
return '<Interval %s>'%self.__str__()
945947

946948
def pretty(self):
947949
''' print up the date date using one of these nice formats..
948950
'''
949-
_quarters = self.minute / 15
951+
_quarters = self.minute // 15
950952
if self.year:
951953
s = self.ngettext("%(number)s year", "%(number)s years",
952954
self.year) % {'number': self.year}
@@ -1040,11 +1042,11 @@ def from_seconds(self, val):
10401042
else:
10411043
self.sign = 1
10421044
self.second = val % 60
1043-
val = val / 60
1045+
val = val // 60
10441046
self.minute = val % 60
1045-
val = val / 60
1047+
val = val // 60
10461048
self.hour = val % 24
1047-
val = val / 24
1049+
val = val // 24
10481050
self.day = val
10491051
self.month = self.year = 0
10501052

@@ -1079,17 +1081,17 @@ def fixTimeOverflow(time):
10791081
sign = seconds<0 and -1 or 1
10801082
seconds *= sign
10811083
S = seconds%60
1082-
seconds /= 60
1084+
seconds //= 60
10831085
M = seconds%60
1084-
seconds /= 60
1086+
seconds //= 60
10851087
H = seconds%24
1086-
d = seconds / 24
1088+
d = seconds // 24
10871089
else:
10881090
months = y*12 + m
10891091
sign = months<0 and -1 or 1
10901092
months *= sign
10911093
m = months%12
1092-
y = months/12
1094+
y = months//12
10931095

10941096
return (sign, y, m, d, H, M, S)
10951097

roundup/support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(self, info, sequence):
7070
self.total = len(sequence)
7171
self.start = self.now = time.time()
7272
self.num = 0
73-
self.stepsize = self.total / 100 or 1
73+
self.stepsize = self.total // 100 or 1
7474
self.steptimes = []
7575
self.display()
7676

test/benchmark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def main(backendname, time=time.time, numissues=10):
5353
db.issue.set(str(i+1), status='2', assignedto='2', nosy=[])
5454
db.issue.set(str(i+1), status='1', assignedto='1',
5555
nosy=['1','2'])
56-
if (i*100/numissues) != pc:
57-
pc = (i*100/numissues)
56+
if (i*100//numissues) != pc:
57+
pc = (i*100//numissues)
5858
sys.stdout.write("%d%%\r"%pc)
5959
sys.stdout.flush()
6060
db.commit()

test/test_multipart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def getIndent(self, line):
7171
if char != ' ':
7272
break
7373
count += 1
74-
return count / 4
74+
return count // 4
7575

7676
class MultipartTestCase(unittest.TestCase):
7777
def setUp(self):

tools/load_tracker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@
5757
db.user.lookup('alpha0')
5858
except:
5959
# add some users
60-
M = N/100
60+
M = N//100
6161
for i in range(M):
6262
print('\ruser', i, ' ', end=' ')
6363
sys.stdout.flush()
64-
if i/17 == 0:
64+
if i//17 == 0:
6565
db.user.create(username=names[i%17])
6666
else:
67-
db.user.create(username=names[i%17]+str(i/17))
67+
db.user.create(username=names[i%17]+str(i//17))
6868

6969
# assignable user list
7070
users = db.user.list()

0 commit comments

Comments
 (0)