← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-true-division into launchpad:master.

Commit message:
Handle / being true division in Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/396326
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-true-division into launchpad:master.
diff --git a/lib/lp/app/browser/stringformatter.py b/lib/lp/app/browser/stringformatter.py
index f66bb43..c791cf7 100644
--- a/lib/lp/app/browser/stringformatter.py
+++ b/lib/lp/app/browser/stringformatter.py
@@ -3,6 +3,8 @@
 
 """TALES formatter for strings."""
 
+from __future__ import division
+
 __metaclass__ = type
 __all__ = [
     'add_word_breaks',
@@ -921,7 +923,7 @@ class FormattersAPI:
     def ellipsize(self, maxlength):
         """Use like tal:content="context/foo/fmt:ellipsize/60"."""
         if len(self._stringtoformat) > maxlength:
-            length = (maxlength - 3) / 2
+            length = (maxlength - 3) // 2
             return (
                 self._stringtoformat[:maxlength - length - 3] + '...' +
                 self._stringtoformat[-length:])
diff --git a/lib/lp/app/browser/tales.py b/lib/lp/app/browser/tales.py
index 268b5bd..115bc0f 100644
--- a/lib/lp/app/browser/tales.py
+++ b/lib/lp/app/browser/tales.py
@@ -3,6 +3,8 @@
 
 """Implementation of the lp: htmlform: fmt: namespaces in TALES."""
 
+from __future__ import division
+
 __metaclass__ = type
 
 from bisect import bisect
@@ -2277,8 +2279,8 @@ class DateTimeFormatterAPI:
         future = delta < timedelta(0, 0, 0)
         delta = abs(delta)
         days = delta.days
-        hours = delta.seconds / 3600
-        minutes = (delta.seconds - (3600 * hours)) / 60
+        hours = delta.seconds // 3600
+        minutes = (delta.seconds - (3600 * hours)) // 60
         seconds = delta.seconds % 60
         result = ''
         if future:
@@ -2341,7 +2343,7 @@ class DateTimeFormatterAPI:
                 number = delta.days
                 unit = 'day'
             else:
-                number = delta.seconds / 60
+                number = delta.seconds // 60
                 if number == 0:
                     return 'less than a minute'
                 unit = 'minute'
@@ -2483,7 +2485,7 @@ class DurationFormatterAPI:
         hours, remaining_seconds = divmod(seconds, 3600)
         ten_minute_chunks = round_half_up(remaining_seconds / 600.0)
         minutes = ten_minute_chunks * 10
-        hours += (minutes / 60)
+        hours += (minutes // 60)
         minutes %= 60
         if hours < 10:
             if minutes:
diff --git a/lib/lp/code/model/sourcepackagerecipe.py b/lib/lp/code/model/sourcepackagerecipe.py
index 10ee27e..9eba658 100644
--- a/lib/lp/code/model/sourcepackagerecipe.py
+++ b/lib/lp/code/model/sourcepackagerecipe.py
@@ -3,6 +3,8 @@
 
 """Implementation of the `SourcePackageRecipe` content type."""
 
+from __future__ import division
+
 __metaclass__ = type
 __all__ = [
     'SourcePackageRecipe',
@@ -406,4 +408,4 @@ class SourcePackageRecipe(Storm):
         if len(durations) == 0:
             return None
         durations.sort(reverse=True)
-        return durations[len(durations) / 2]
+        return durations[len(durations) // 2]
diff --git a/lib/lp/code/tests/helpers.py b/lib/lp/code/tests/helpers.py
index fae251a..c9d980c 100644
--- a/lib/lp/code/tests/helpers.py
+++ b/lib/lp/code/tests/helpers.py
@@ -3,7 +3,12 @@
 
 """Helper functions for code testing live here."""
 
-from __future__ import absolute_import, print_function, unicode_literals
+from __future__ import (
+    absolute_import,
+    division,
+    print_function,
+    unicode_literals,
+    )
 
 __metaclass__ = type
 __all__ = [
@@ -212,7 +217,7 @@ def make_project_cloud_data(factory, details):
         project = factory.makeProduct(name=project_name)
         start_date = last_commit - delta * (num_commits - 1)
         gen = time_counter(start_date, delta)
-        commits_each = num_commits / num_authors
+        commits_each = num_commits // num_authors
         for committer in range(num_authors - 1):
             make_project_branch_with_revisions(
                 factory, gen, project, commits_each)
diff --git a/lib/lp/registry/browser/distribution.py b/lib/lp/registry/browser/distribution.py
index c499689..f638654 100644
--- a/lib/lp/registry/browser/distribution.py
+++ b/lib/lp/registry/browser/distribution.py
@@ -3,6 +3,8 @@
 
 """Browser views for distributions."""
 
+from __future__ import division
+
 __metaclass__ = type
 
 __all__ = [
@@ -1258,9 +1260,9 @@ class DistributionMirrorsView(LaunchpadView):
         if throughput < 1000:
             return str(throughput) + ' Kbps'
         elif throughput < 1000000:
-            return str(throughput / 1000) + ' Mbps'
+            return str(throughput // 1000) + ' Mbps'
         else:
-            return str(throughput / 1000000) + ' Gbps'
+            return str(throughput // 1000000) + ' Gbps'
 
     @cachedproperty
     def total_throughput(self):