A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://groups.google.com/group/comp.lang.python/browse_frm/thread/801f227fceff4066 below:

integer subclass range behavior

josephar...@gmail.com

unread, Dec 19, 2007, 10:11:49 PM12/19/07

You do not have permission to delete messages in this group

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to

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!

Gabriel Genellina

unread, Dec 20, 2007, 1:42:25 AM12/20/07

You do not have permission to delete messages in this group

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to pytho...@python.org

En Wed, 19 Dec 2007 18:11:49 -0300,

josephar...@gmail.com

<

josephar...@gmail.com

> escribió:

> 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
>
> Interesting!

Yes. But much more interesting would be to report this on the bug tracker
http://bugs.python.org else it will fade away...

--
Gabriel Genellina

josephar...@gmail.com

unread, Dec 20, 2007, 2:20:17 AM12/20/07

You do not have permission to delete messages in this group

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to

On Dec 19, 7:42 pm, "Gabriel Genellina" <

gagsl-...@yahoo.com.ar

>

wrote:

> En Wed, 19 Dec 2007 18:11:49 -0300,

josepharmbrus...@gmail.com

> <

josepharmbrus...@gmail.com

> escribió:


>
>
>
> > 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
>
> > Interesting!
>

> Yes. But much more interesting would be to report this on the bug tracker

http://bugs.python.orgelse

it will fade away...

>

> --

> Gabriel Genellina


Gabriel,

I usually do that... But from what i've learned, most things i've
thought are bugs, turn out to be that way for a good reason. I was
playing it safe on this one :-)

Joseph Armbruster

Gabriel Genellina

unread, Dec 20, 2007, 2:51:58 AM12/20/07

You do not have permission to delete messages in this group

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to pytho...@python.org

En Wed, 19 Dec 2007 22:20:17 -0300,

josephar...@gmail.com

<

josephar...@gmail.com

> escribió:

> On Dec 19, 7:42 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
> wrote:
>> En Wed, 19 Dec 2007 18:11:49 -0300, josepharmbrus...@gmail.com
>> <josepharmbrus...@gmail.com> escribió:
>>
>> > 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
>>
>> > Interesting!
>>
>> Yes. But much more interesting would be to report this on the bug

>> tracker http://bugs.python.org else it will fade away...
>>

> I usually do that... But from what i've learned, most things i've
> thought are bugs, turn out to be that way for a good reason. I was
> playing it safe on this one :-)

Well, it works on 2.5, and I don't see why it should not work on 3.0 too,
so IMHO this is a genuine bug. That means only that when some god or
demi-god explains the good reasons for this failure, we both will say a
big "Ahhhhh! That was it!" :)

--
Gabriel Genellina


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4