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 asvetlov, docs@python, ezio.melotti, mark.dickinson, paddy3118, serhiy.storchaka, woparry
Date 2013-05-26.10:35:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1369564519.03.0.293486843314.issue16580@psf.upfronthosting.co.za>
In-reply-to
Content
The `from_bytes` example code looks fine to me, except that I'd probably use `enumerate` in the iteration;  i.e.,

    sum(b << 8*i for i, b in enumerate(little_ordered))

instead of

    sum(little_ordered[i] << i*8 for i in range(len(little_ordered)))

Also, in:

   if signed and little_ordered and (little_ordered[-1] & 0x80):

I wondered why you needed the `little_ordered` check.  But I see that `int.from_bytes(b'', 'little', signed=True)` produces `0`, which is a little bit disappointing:  I was expecting an exception.  (A signed format should have a sign bit, which is impossible if the length of the byte string is 0.)

The `to_bytes` example code is missing range checks for the input.  It may be clearer to simply state that in the docs, instead of modifying the example code to add the range checks.
History
Date User Action Args
2013-05-26 10:35:19mark.dickinsonsetrecipients: + mark.dickinson, paddy3118, ezio.melotti, asvetlov, docs@python, serhiy.storchaka, woparry
2013-05-26 10:35:19mark.dickinsonsetmessageid: <1369564519.03.0.293486843314.issue16580@psf.upfronthosting.co.za>
2013-05-26 10:35:19mark.dickinsonlinkissue16580 messages
2013-05-26 10:35:18mark.dickinsoncreate