morfizm (morfizm) wrote,

Python doc

My first bug found in Python doc:

1. "Note that numeric literals do not include a sign; a phrase like -1 is actually an expression composed of the unary operator ‘-‘ and the literal 1." (Python v2.7.1 language reference, Literals, 2.4.3. Numeric literals)

2. "Plain integer literals that are above the largest representable plain integer (e.g., 2147483647 when using 32-bit arithmetic) are accepted as if they were long integers instead." (Python v2.7.1 language reference, Literals, 2.4.4. Integer and long integer literals)

Based on these two things, I'd expect "-2147483648" be interpreted as long, because 2147483648 is long and unary - of long will result in long. The latter is supported by:

>>> -(2147483647+1)

However, "-2147483648" is not long, it's int:

>>> -2147483648

Which is good, but which means the doc is incorrect. This is a minor thing, but I am disappointed, because if my reasoning is correct, it means the doc is not trustworthy.
Tags: in english, software development

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.