This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients alexandre.vassalotti, bob.ippolito, josiahcarlson, loewis, mark.dickinson, mwh, pitrou, rhettinger, tim.peters
Date 2009-08-15.11:18:34
SpamBayes Score 1.2240209e-13
Marked as misclassified No
Message-id <1250335117.21.0.553963564027.issue1023290@psf.upfronthosting.co.za>
In-reply-to
Content
Thanks for this patch, Alexandre!

I'm +1 on applying a version of this patch.

I'm not convinced that the variable-length part (i.e., fixed_length=None) of 
int.as_bytes is all that useful;  the choices that need to be made about how to 
represent integers seem too arbitrary to standardize in this function.  In effect, the 
non-fixed-length version provides yet another serialization mechanism for integers, 
and there's no shortage of existing mechanisms.  As I see it, the purpose of the 
as_bytes and frombytes methods is lower-level:  providing a basic operation that will 
be used by various serialization methods.  So I'd suggest making fixed_length a 
required argument;  code requiring non-fixed-length conversions can use int.bit_length 
to help calculate the length they want.


<bikeshedding>
I'm also not convinced by the defaults for the other two arguments:  personally, I'd 
expect to need unsigned more often than signed, and little-endian more often than big-
endian.

Perhaps the byteorder should default to the native byteorder when not explicitly 
given?  That would bring the conversions more closely in line with the struct module.

Another possibility:  instead of 'little_endian', have a parameter 'byteorder' taking 
the value 'big' or 'little';  this would enable use of byteorder=sys.byteorder to 
explicitly specify native byteorder, and avoids bias towards one particular byte 
order.

Can we use 'length' instead of 'fixed_length'?
</bikeshedding>

There's a typo in the test_long part of the patch: aserrtRaises -> assertRaises;  
apart from that, all tests pass on OS X 10.5/Intel with this patch applied.

I'm in the process of looking at the code more thoroughly.

See related Python-ideas thread at:

http://mail.python.org/pipermail/python-ideas/2009-August/005489.html
History
Date User Action Args
2009-08-15 11:18:37mark.dickinsonsetrecipients: + mark.dickinson, mwh, tim.peters, loewis, rhettinger, josiahcarlson, bob.ippolito, pitrou, alexandre.vassalotti
2009-08-15 11:18:37mark.dickinsonsetmessageid: <1250335117.21.0.553963564027.issue1023290@psf.upfronthosting.co.za>
2009-08-15 11:18:36mark.dickinsonlinkissue1023290 messages
2009-08-15 11:18:34mark.dickinsoncreate