473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

integer subclass range behavior

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!
Dec 19 '07 #1
3 1127
En Wed, 19 Dec 2007 18:11:49 -0300, jo**************@gmail.com
<jo**************@gmail.comescribió:
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

Dec 20 '07 #2
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.comescribió:
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
Dec 20 '07 #3
En Wed, 19 Dec 2007 22:20:17 -0300, jo**************@gmail.com
<jo**************@gmail.comescribió:
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.comescribió:
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

Dec 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gerry Sutton | last post by:
Hi All! I have noticed a strange behavior when using a constant identifier to initialize an instance list variable in a base class and then trying to modifying the list in subclasses by using...
2
by: REH | last post by:
If the is_modulo field of the numeric_limits class is true for signed integer types, can I assume that overflow for such types is defined behavior? If so, is the behavior the same regardless of...
28
by: anonymous | last post by:
I have couple of questions related to array addresses. As they belong to the same block, I am putting them here in one single post. I hope nobody minds: char array; int address; Questions...
25
by: junky_fellow | last post by:
Is there any way by which the overflow during addition of two integers may be detected ? eg. suppose we have three unsigned integers, a ,b, c. we are doing a check like if ((a +b) > c) do...
4
by: rz0 | last post by:
Hi all, This is a question about both C89 and C99 and is based on my partial reading of the standard drafts (one from before C89 but mainly N1124). If appropriate, please give a...
17
by: Yogi_Bear_79 | last post by:
I have the following code: sscanf(line, "%d", n_ptr) !=1 || n_ptr <=0; It only partially works. If the user types a character other than 0-9 to start the string it fails. However as long as...
40
by: Robert Seacord | last post by:
The CERT/CC has released a beta version of a secure integer library for the C Programming Language. The library is available for download from the CERT/CC Secure Coding Initiative web page at:...
4
by: Kurt Smith | last post by:
Hi List: Class inheritance noob here. For context, I have the following base class and subclass: class Base(object): def __init__(self, val): self.val = val
12
by: lithiumcat | last post by:
Hi, I bothered you a while back about storing integer values in void*. Now in a completely unrelated context, I'm trying to store pointer values in an integer type. So the basic question is,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.