Merge ~cjwatson/launchpad:py3-true-division into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: f32dbb8ec9e88bffbd39234dd83773051c2d76cf
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-true-division
Merge into: launchpad:master
Diff against target: 135 lines (+23/-10)
5 files modified
lib/lp/app/browser/stringformatter.py (+3/-1)
lib/lp/app/browser/tales.py (+6/-4)
lib/lp/code/model/sourcepackagerecipe.py (+3/-1)
lib/lp/code/tests/helpers.py (+7/-2)
lib/lp/registry/browser/distribution.py (+4/-2)
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+396326@code.launchpad.net

Commit message

Handle / being true division in Python 3

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/app/browser/stringformatter.py b/lib/lp/app/browser/stringformatter.py
2index f66bb43..c791cf7 100644
3--- a/lib/lp/app/browser/stringformatter.py
4+++ b/lib/lp/app/browser/stringformatter.py
5@@ -3,6 +3,8 @@
6
7 """TALES formatter for strings."""
8
9+from __future__ import division
10+
11 __metaclass__ = type
12 __all__ = [
13 'add_word_breaks',
14@@ -921,7 +923,7 @@ class FormattersAPI:
15 def ellipsize(self, maxlength):
16 """Use like tal:content="context/foo/fmt:ellipsize/60"."""
17 if len(self._stringtoformat) > maxlength:
18- length = (maxlength - 3) / 2
19+ length = (maxlength - 3) // 2
20 return (
21 self._stringtoformat[:maxlength - length - 3] + '...' +
22 self._stringtoformat[-length:])
23diff --git a/lib/lp/app/browser/tales.py b/lib/lp/app/browser/tales.py
24index 268b5bd..115bc0f 100644
25--- a/lib/lp/app/browser/tales.py
26+++ b/lib/lp/app/browser/tales.py
27@@ -3,6 +3,8 @@
28
29 """Implementation of the lp: htmlform: fmt: namespaces in TALES."""
30
31+from __future__ import division
32+
33 __metaclass__ = type
34
35 from bisect import bisect
36@@ -2277,8 +2279,8 @@ class DateTimeFormatterAPI:
37 future = delta < timedelta(0, 0, 0)
38 delta = abs(delta)
39 days = delta.days
40- hours = delta.seconds / 3600
41- minutes = (delta.seconds - (3600 * hours)) / 60
42+ hours = delta.seconds // 3600
43+ minutes = (delta.seconds - (3600 * hours)) // 60
44 seconds = delta.seconds % 60
45 result = ''
46 if future:
47@@ -2341,7 +2343,7 @@ class DateTimeFormatterAPI:
48 number = delta.days
49 unit = 'day'
50 else:
51- number = delta.seconds / 60
52+ number = delta.seconds // 60
53 if number == 0:
54 return 'less than a minute'
55 unit = 'minute'
56@@ -2483,7 +2485,7 @@ class DurationFormatterAPI:
57 hours, remaining_seconds = divmod(seconds, 3600)
58 ten_minute_chunks = round_half_up(remaining_seconds / 600.0)
59 minutes = ten_minute_chunks * 10
60- hours += (minutes / 60)
61+ hours += (minutes // 60)
62 minutes %= 60
63 if hours < 10:
64 if minutes:
65diff --git a/lib/lp/code/model/sourcepackagerecipe.py b/lib/lp/code/model/sourcepackagerecipe.py
66index 10ee27e..9eba658 100644
67--- a/lib/lp/code/model/sourcepackagerecipe.py
68+++ b/lib/lp/code/model/sourcepackagerecipe.py
69@@ -3,6 +3,8 @@
70
71 """Implementation of the `SourcePackageRecipe` content type."""
72
73+from __future__ import division
74+
75 __metaclass__ = type
76 __all__ = [
77 'SourcePackageRecipe',
78@@ -406,4 +408,4 @@ class SourcePackageRecipe(Storm):
79 if len(durations) == 0:
80 return None
81 durations.sort(reverse=True)
82- return durations[len(durations) / 2]
83+ return durations[len(durations) // 2]
84diff --git a/lib/lp/code/tests/helpers.py b/lib/lp/code/tests/helpers.py
85index fae251a..c9d980c 100644
86--- a/lib/lp/code/tests/helpers.py
87+++ b/lib/lp/code/tests/helpers.py
88@@ -3,7 +3,12 @@
89
90 """Helper functions for code testing live here."""
91
92-from __future__ import absolute_import, print_function, unicode_literals
93+from __future__ import (
94+ absolute_import,
95+ division,
96+ print_function,
97+ unicode_literals,
98+ )
99
100 __metaclass__ = type
101 __all__ = [
102@@ -212,7 +217,7 @@ def make_project_cloud_data(factory, details):
103 project = factory.makeProduct(name=project_name)
104 start_date = last_commit - delta * (num_commits - 1)
105 gen = time_counter(start_date, delta)
106- commits_each = num_commits / num_authors
107+ commits_each = num_commits // num_authors
108 for committer in range(num_authors - 1):
109 make_project_branch_with_revisions(
110 factory, gen, project, commits_each)
111diff --git a/lib/lp/registry/browser/distribution.py b/lib/lp/registry/browser/distribution.py
112index c499689..f638654 100644
113--- a/lib/lp/registry/browser/distribution.py
114+++ b/lib/lp/registry/browser/distribution.py
115@@ -3,6 +3,8 @@
116
117 """Browser views for distributions."""
118
119+from __future__ import division
120+
121 __metaclass__ = type
122
123 __all__ = [
124@@ -1258,9 +1260,9 @@ class DistributionMirrorsView(LaunchpadView):
125 if throughput < 1000:
126 return str(throughput) + ' Kbps'
127 elif throughput < 1000000:
128- return str(throughput / 1000) + ' Mbps'
129+ return str(throughput // 1000) + ' Mbps'
130 else:
131- return str(throughput / 1000000) + ' Gbps'
132+ return str(throughput // 1000000) + ' Gbps'
133
134 @cachedproperty
135 def total_throughput(self):

Subscribers

People subscribed via source and target branches

to status/vote changes: