int vs long is a python 2.x annoyance.  It goes away in 3.x as the int
vs long distinction disappears.

Regardless, the correct thing to do in 2.x is to accept both int and
long types, this unit test is being too strict.  What matters is the
actual value, not the exact type.  In
ReadScalarTestHelper line 107 the following assertion is too strict:

    self.assert_(isinstance(result, type(expected_result)))

This should either be relaxed when type(expected_result) is int or
long, or you should add an additional parameter to the function
expected_result_types and use that as the second parameter to
isinstance (it can be a singluar type or a sequence of valid types).
Both int and long should be allowed.


On Mon, Oct 6, 2008 at 7:35 PM, Kenton Varda <[EMAIL PROTECTED]> wrote:
> [+petar]
> (Same problem as the other thread.)
> On Sun, Oct 5, 2008 at 2:41 AM, Iustin Pop <[EMAIL PROTECTED]> wrote:
>> Hi there,
>> Revision 50 changed the following line in
>> python/google/protobuf/internal/
>> 122: ['sfixed32', decoder.Decoder.ReadSFixed32, -1,
>>      'ReadLittleEndian32', 0xffffffff],
>> (in testReadScalars). The change is going from the above "-1" to
>> "long(-1)". While this passes ok on i386, it fails on amd64:
>> i386: result is <type 'long'>, expected is <type 'long'>
>> amd64: result is <type 'int'>, expected is <type 'long'>
>> I don't understand exactly what's going on, but I think the problem is
>> that an i386 system cannot represent that constant as int, but amd64 can
>> (not sure why...):
>> $ python32 -c 'print type(0xffffffff)'
>> <type 'long'>
>> $ python64 -c 'print type(0xffffffff)'
>> <type 'int'>
>> Of course, just reverting the 'long(-1)' change makes the test fail on
>> i386.
>> So, is this a genuine failure in the code, or is it just a bad unittest
>> that I can workaround by changing 0xffffffff to long(0xffffffff)?
>> I'm thinking of applying this patch in order to make the tests pass on
>> both platforms:
>> $ svn diff
>> Index: python/google/protobuf/internal/
>> ===================================================================
>> --- python/google/protobuf/internal/     (revision 64)
>> +++ python/google/protobuf/internal/     (working copy)
>> @@ -120,7 +120,7 @@
>>         ['fixed64', decoder.Decoder.ReadFixed64, 0xffffffffffffffff,
>>         'ReadLittleEndian64', 0xffffffffffffffff],
>>         ['sfixed32', decoder.Decoder.ReadSFixed32, long(-1),
>> -         'ReadLittleEndian32', 0xffffffff],
>> +         'ReadLittleEndian32', long(0xffffffff)],
>>         ['sfixed64', decoder.Decoder.ReadSFixed64, long(-1),
>>          'ReadLittleEndian64', 0xffffffffffffffff],
>>         ['float', decoder.Decoder.ReadFloat, 0.0,
>> regards,
>> iustin
> >

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at

Reply via email to