int vs long

Peter Otten __peter__ at web.de
Mon Jun 4 05:34:10 EDT 2007


Douglas Woodrow wrote:

> On Mon, 4 Jun 2007 10:50:14, Peter Otten <__peter__ at web.de> wrote
>>>>
>>>> This is fixed in Python2.5:
>>>>
>>> Hm, my test above was from 2.5!?
>>
>>Then your installation is broken. What does
>>
>>>>> import itertools
>>>>> itertools
>><module 'itertools' from
>>'/usr/local/lib/python2.5/lib-dynload/itertools.so'>
>>
>>print?
> 
> 
> Maybe it's a problem with the Windows build of Python 2.5
> 
> ,----
> | Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310
> | 32 bit (Intel)] on win32
> | Type "help", "copyright", "credits" or "license" for more information.
> | >>> import sys
> | >>> import itertools
> | >>> itertools
> | <module 'itertools' (built-in)>
> | >>> c = itertools.count(sys.maxint)
> | >>> c.next()
> | Traceback (most recent call last):
> |   File "<stdin>", line 1, in <module>
> | OverflowError: cannot count beyond LONG_MAX
> | >>>
> `----
> 

Revision 51950 check-in message:
"""
* regression bug, count_next was coercing a Py_ssize_t to an unsigned
Py_size_t
  which breaks negative counts
* added test for negative numbers
will backport to 2.5.1
"""

Turns out I was wrong, count() does not escalate from int to long correctly.
It just had an unsigned internal counter in 2.5. Sorry for the confusion.

Peter




More information about the Python-list mailing list