[tor-commits] [nyx/master] Standardize on integer division

atagar at torproject.org atagar at torproject.org
Sun Aug 28 18:29:22 UTC 2016


commit 168561c5ad3584212f8cfd993f082fbb0da4d7dd
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Aug 28 10:11:30 2016 -0700

    Standardize on integer division
    
    Python 3.x changes to do float division. Using '//' to explicitly do integer
    division. This changes testing failures as follows...
    
      from: FAILED (failures=3, errors=15)
      to: FAILED (failures=8, errors=5)
---
 nyx/panel/graph.py | 8 ++++----
 nyx/popups.py      | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/nyx/panel/graph.py b/nyx/panel/graph.py
index 492037e..250c0e6 100644
--- a/nyx/panel/graph.py
+++ b/nyx/panel/graph.py
@@ -648,7 +648,7 @@ def _x_axis_labels(interval, columns):
   interval_spacing = 10 if columns >= WIDE_LABELING_GRAPH_COL else 5
   previous_units, decimal_precision = None, 0
 
-  for i in range((columns - 4) / interval_spacing):
+  for i in range((columns - 4) // interval_spacing):
     x = (i + 1) * interval_spacing
     time_label = str_tools.time_label(x * interval_sec, decimal_precision)
 
@@ -676,15 +676,15 @@ def _y_axis_labels(subgraph_height, data, min_bound, max_bound):
     subgraph_height - 1: data.y_axis_label(min_bound),
   }
 
-  ticks = (subgraph_height - 5) / 2
+  ticks = (subgraph_height - 5) // 2
 
   for i in range(ticks):
     row = subgraph_height - (2 * i) - 5
 
-    if subgraph_height % 2 == 0 and i >= (ticks / 2):
+    if subgraph_height % 2 == 0 and i >= (ticks // 2):
       row -= 1  # make extra gap be in the middle when we're an even size
 
-    val = (max_bound - min_bound) * (subgraph_height - row - 3) / (subgraph_height - 3)
+    val = (max_bound - min_bound) * (subgraph_height - row - 3) // (subgraph_height - 3)
 
     if val not in (min_bound, max_bound):
       y_axis_labels[row + 2] = data.y_axis_label(val)
diff --git a/nyx/popups.py b/nyx/popups.py
index 8cadf05..e9fa1db 100644
--- a/nyx/popups.py
+++ b/nyx/popups.py
@@ -233,7 +233,7 @@ def show_descriptor(fingerprint, color, is_close_key):
 
   for line in lines:
     width = min(screen_size.width, max(width, len(line) + line_number_width + 5))
-    height += len(line) / (screen_size.width - line_number_width - 5)  # extra lines due to text wrap
+    height += len(line) // (screen_size.width - line_number_width - 5)  # extra lines due to text wrap
 
   with nyx.curses.CURSES_LOCK:
     nyx.curses.draw(lambda subwindow: subwindow.addstr(0, 0, ' ' * 500), top = _top(), height = 1)  # hides title below us
@@ -454,7 +454,7 @@ def select_event_types(initial_selection):
 
   with nyx.curses.CURSES_LOCK:
     while True:
-      nyx.curses.draw(_render, top = _top(), width = 80, height = (len(events) / 3) + 10)
+      nyx.curses.draw(_render, top = _top(), width = 80, height = (len(events) // 3) + 10)
       key = nyx.curses.key_input()
 
       if key.match('up'):





More information about the tor-commits mailing list