• Thomas Wouters's avatar
    Fix int() and long() to repr() their argument when formatting the exception, · 9cb28bea
    Thomas Wouters yazdı
    to avoid confusing situations like:
    
    >>> int("")
    ValueError: invalid literal for int():
    >>> int("2\n\n2")
    ValueError: invalid literal for int(): 2
    
    2
    
    Also report the base used, to avoid:
    
    ValueError: invalid literal for int(): 2
    
    They now report:
    
    >>> int("")
    ValueError: invalid literal for int() with base 10: ''
    >>> int("2\n\n2")
    ValueError: invalid literal for int() with base 10: '2\n\n2'
    >>> int("2", 2)
    ValueError: invalid literal for int() with base 2: '2'
    
    (Reporting the base could be avoided when base is 10, which is the default,
    but hrm.) Another effect of these changes is that the errormessage can be
    longer; before, it was cut off at about 250 characters. Now, it can be up to
    four times as long, as the unrepr'ed string is cut off at 200 characters,
    instead.
    
    No tests were added or changed, since testing for exact errormsgs is (pardon
    the pun) somewhat errorprone, and I consider not testing the exact text
    preferable. The actually changed code is tested frequent enough in the
    test_builtin test as it is (120 runs for each of ints and longs.)
    9cb28bea
intobject.c 28.7 KB