Patchwork py3: use integer division instead of `int(...)` call

login
register
mail settings
Submitter Boris Feld
Date Feb. 4, 2019, 11:17 a.m.
Message ID <23e2af1929c66ab34e9f.1549279022@pc62.home>
Download mbox | patch
Permalink /patch/38358/
State Accepted
Headers show

Comments

Boris Feld - Feb. 4, 2019, 11:17 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1549184503 -3600
#      Sun Feb 03 10:01:43 2019 +0100
# Node ID 23e2af1929c66ab34e9f09bb2caec298e9a8e71c
# Parent  9955776e2adf36c5baabad8f73840a0cdfa19589
# EXP-Topic div-cleanup
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 23e2af1929c6
py3: use integer division instead of `int(...)` call

Changeset 38a82e0333c9 and 7f853549823b introduced explicit conversion to
integer to work around the division behavior change from python2 to python3.
Using the integer division operator is a simpler and clearer way to achieve
this.
Yuya Nishihara - Feb. 4, 2019, 11:39 a.m.
On Mon, 04 Feb 2019 12:17:02 +0100, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1549184503 -3600
> #      Sun Feb 03 10:01:43 2019 +0100
> # Node ID 23e2af1929c66ab34e9f09bb2caec298e9a8e71c
> # Parent  9955776e2adf36c5baabad8f73840a0cdfa19589
> # EXP-Topic div-cleanup
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 23e2af1929c6
> py3: use integer division instead of `int(...)` call

Queued, thanks.

Patch

diff --git a/hgext/remotefilelog/datapack.py b/hgext/remotefilelog/datapack.py
--- a/hgext/remotefilelog/datapack.py
+++ b/hgext/remotefilelog/datapack.py
@@ -242,8 +242,8 @@  class datapack(basepack.basepack):
             entry = index[end:end + entrylen]
         else:
             while start < end - entrylen:
-                mid = start  + (end - start) / 2
-                mid = int(mid - ((mid - params.indexstart) % entrylen))
+                mid = start  + (end - start) // 2
+                mid = mid - ((mid - params.indexstart) % entrylen)
                 midnode = index[mid:mid + NODELENGTH]
                 if midnode == node:
                     entry = index[mid:mid + entrylen]
diff --git a/tests/test-remotefilelog-datapack.py b/tests/test-remotefilelog-datapack.py
--- a/tests/test-remotefilelog-datapack.py
+++ b/tests/test-remotefilelog-datapack.py
@@ -292,7 +292,7 @@  class datapacktestsbase(object):
 
         class testdatapackstore(datapack.datapackstore):
             # Ensures that we are not keeping everything in the cache.
-            DEFAULTCACHESIZE = int(numpacks / 2)
+            DEFAULTCACHESIZE = numpacks // 2
 
         store = testdatapackstore(uimod.ui(), packdir)