[PATCHES] begone python long

Douglas Bagnall douglas.bagnall at catalyst.net.nz
Wed Oct 10 04:44:22 UTC 2018


On 8/10/18 10:47 PM, Noel Power wrote:
> Hi Douglas
> On 04/10/2018 03:40, Douglas Bagnall via samba-technical wrote:
>> Tim was fixing the (py3-incompatible, py2-wrong) use of Python long() for a C binding that took C longs which it then squeezed into time_t, and I thought I'd look for other python longs. There aren't many, if we neglect third_party/. After this there will be one, but Python 3 won't see it. cheers, Douglas
> [...]
>> @ -831,7 +831,9 @@ def int64range2str(value):
>>      :param value: The int64 range
>>      :return: A string of the representation of the range
>>      """
>> -
>> -    lvalue = long(value)
>> +    if PY3:
>> +        lvalue = int(value)
>> +    else:
>> +        lvalue = long(value)
>>      str = "%d-%d" % (lvalue &0xFFFFFFFF, lvalue >>32)
>>      return str
> 
> I don't think we need the if PY3: above, simply changing the line as follows
> -    lvalue = long(value)
> +    value = int(value)
> 
> afaics should be enough. Python2 int function will return a long if you pass it something outside the the integer range. This will avoid another PY3 specific test in the code which we try to avoid wherever possible.

Yep, that's obviously better. I somehow had the idea that Python 2.6
would not do that, but it does (since 2.4 or so).

> With that change RB+ from me

thanks.

Douglas



More information about the samba-technical mailing list