[Python-Dev] integer subclass range behavior
Guido van Rossum
guido at python.org
Thu Dec 20 04:31:46 CET 2007
Can you submit a bug at bugs.python.org?
The minimal example I found:
>>> class a(int): pass
...
>>> for i in range(0, a(5)): pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: Objects/longobject.c:400: bad argument to internal function
>>>
On Dec 19, 2007 5:38 PM, Joseph Armbruster <josepharmbruster at gmail.com> wrote:
> All,
>
> I posted this up to comp.lang.python earlier today and asked a few questions
> around IRC. The general consensus appeared to be that this was a bug. Before
> opening up an issue on it, I wanted to run it by this list first (just in case)
> Here is a copy / paste from comp.lang.python:
>
> URL:
>
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/801f227fceff4066#e0305608a5931af1
>
> Post:
>
> I was wondering what would happen, so I tried this out for the heck of it with:
> Python 3.0a2 (py3k:59572M, Dec 19 2007, 15:54:07) [MSC v.1500 32 bit (Intel)]
> on win32
>
> class a(int):
> def __new__(cls,number):
> return int.__new__(cls,number)
>
> for x in range(0,a(5)):
> print(x)
>
> Which resulted in a:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "a.py", line 5, in <module>
> for x in range(0,a(5)):
> SystemError: ..\Objects\longobject.c:400: bad argument to internal
> function
> [41030 refs]
>
> It looks like the rangeobject performs a FitsInLong test on each of
> the parameters to range, which uses the function
> _PyLong_FitsInLong(PyObject *vv) within longobject.c. In tern, this
> performs a typecheck: #define PyLong_CheckExact(op) (Py_TYPE(op) ==
> &PyLong_Type) that fails.
>
> Interesting!
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
>
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list