Patchwork [06,of,10,py3] bundle2: use modern Python division

login
register
mail settings
Submitter Augie Fackler
Date Aug. 1, 2017, 8:34 p.m.
Message ID <4c1f4e109bf90a8352a2.1501619674@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/22612/
State Accepted
Headers show

Comments

Augie Fackler - Aug. 1, 2017, 8:34 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1500909456 14400
#      Mon Jul 24 11:17:36 2017 -0400
# Node ID 4c1f4e109bf90a8352a25a6b45a80fabcac6306b
# Parent  7d68e38eb849015f034a0cbd66990777e635e8f6
bundle2: use modern Python division

This was failing on Python 3 because the / was returning a float,
which was then making the __mul__ on a bytes sad.
via Mercurial-devel - Aug. 14, 2017, 6:17 p.m.
On Tue, Aug 1, 2017 at 1:34 PM, Augie Fackler <raf@durin42.com> wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1500909456 14400
> #      Mon Jul 24 11:17:36 2017 -0400
> # Node ID 4c1f4e109bf90a8352a25a6b45a80fabcac6306b
> # Parent  7d68e38eb849015f034a0cbd66990777e635e8f6
> bundle2: use modern Python division
>
> This was failing on Python 3 because the / was returning a float,
> which was then making the __mul__ on a bytes sad.
>
> diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
> --- a/mercurial/bundle2.py
> +++ b/mercurial/bundle2.py
> @@ -145,7 +145,7 @@ future, dropping the stream may become a
>  preserve.
>  """
>
> -from __future__ import absolute_import
> +from __future__ import absolute_import, division

Is the import necessary? IIUC, that is for making '/' be for floating
point (which we don't care about here).

>
>  import errno
>  import re
> @@ -994,7 +994,7 @@ class bundlepart(object):
>          for key, value in advpar:
>              parsizes.append(len(key))
>              parsizes.append(len(value))
> -        paramsizes = _pack(_makefpartparamsizes(len(parsizes) / 2), *parsizes)
> +        paramsizes = _pack(_makefpartparamsizes(len(parsizes) // 2), *parsizes)
>          header.append(paramsizes)
>          # key, value
>          for key, value in manpar:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Augie Fackler - Aug. 14, 2017, 6:40 p.m.
> On Aug 14, 2017, at 14:17, Martin von Zweigbergk <martinvonz@google.com> wrote:
> 
> On Tue, Aug 1, 2017 at 1:34 PM, Augie Fackler <raf@durin42.com> wrote:
>> # HG changeset patch
>> # User Augie Fackler <augie@google.com>
>> # Date 1500909456 14400
>> #      Mon Jul 24 11:17:36 2017 -0400
>> # Node ID 4c1f4e109bf90a8352a25a6b45a80fabcac6306b
>> # Parent  7d68e38eb849015f034a0cbd66990777e635e8f6
>> bundle2: use modern Python division
>> 
>> This was failing on Python 3 because the / was returning a float,
>> which was then making the __mul__ on a bytes sad.
>> 
>> diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
>> --- a/mercurial/bundle2.py
>> +++ b/mercurial/bundle2.py
>> @@ -145,7 +145,7 @@ future, dropping the stream may become a
>> preserve.
>> """
>> 
>> -from __future__ import absolute_import
>> +from __future__ import absolute_import, division
> 
> Is the import necessary? IIUC, that is for making '/' be for floating
> point (which we don't care about here).

It's not strictly necessary, but it ensures that / behaves consistently on both Pythons and makes it so that the single-/ form is also broken on Python 2 (so nobody gets ideas and "fixes" the //.)

> 
>> 
>> import errno
>> import re
>> @@ -994,7 +994,7 @@ class bundlepart(object):
>>         for key, value in advpar:
>>             parsizes.append(len(key))
>>             parsizes.append(len(value))
>> -        paramsizes = _pack(_makefpartparamsizes(len(parsizes) / 2), *parsizes)
>> +        paramsizes = _pack(_makefpartparamsizes(len(parsizes) // 2), *parsizes)
>>         header.append(paramsizes)
>>         # key, value
>>         for key, value in manpar:
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel@mercurial-scm.org
>> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -145,7 +145,7 @@  future, dropping the stream may become a
 preserve.
 """
 
-from __future__ import absolute_import
+from __future__ import absolute_import, division
 
 import errno
 import re
@@ -994,7 +994,7 @@  class bundlepart(object):
         for key, value in advpar:
             parsizes.append(len(key))
             parsizes.append(len(value))
-        paramsizes = _pack(_makefpartparamsizes(len(parsizes) / 2), *parsizes)
+        paramsizes = _pack(_makefpartparamsizes(len(parsizes) // 2), *parsizes)
         header.append(paramsizes)
         # key, value
         for key, value in manpar: