473,487 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

__getslice__ passed INT_MAX rather than sys.maxint for missing endpoint?

Hi, I don't actually know Python; I'm just trying to debug a problem
I encounted in another program, so apologies if this has been
covered before. I did do some Google searches though, and didn't
find anything that specifically addressed this :)

According to the documentation at
<http://docs.python.org/ref/sequence-methods.html>, __getslice__
is passed sys.maxint for a missing endpoint (foo[i:]). However, as
far as I can tell, it's actually passing INT_MAX. I'm running Python
2.4 on an Alpha running NetBSD 2.0, an LP64 platform, so the two
aren't the same. INT_MAX is 2^32-1, whereas sys.maxint is LONG_MAX:
2^64-1.

So, am I misunderstanding things, or is this a doc bug, or a code bug?

FWIW, the problem I encountered was some code that did something like:
def __getslice__(self, a, b):
if b == maxint:
b = self.length # this never got executed, causing problems
--
Name: Dave Huang | Mammal, mammal / their names are called /
INet: kh**@azeotrope.org | they raise a paw / the bat, the cat /
FurryMUCK: Dahan | dolphin and dog / koala bear and hog -- TMBG
Dahan: Hani G Y+C 29 Y++ L+++ W- C++ T++ A+ E+ S++ V++ F- Q+++ P+ B+ PA+ PL++
Jul 18 '05 #1
1 2410
Dave Huang wrote:
So, am I misunderstanding things, or is this a doc bug, or a code bug?


Strictly speaking, it is both a doc bug and a code bug.

In CPython, indexes are typically represented internally through C int,
and this is also used to represent the size of the standard containers
(lists, strings, tuples). So "infinity" is appropriately represented
as INT_MAX for such containers.

OTOH, Python int objects are implemented through C longs, so sys.maxint
might be larger if longs are wider than ints. For the indexing issue,
this should be irrelevant: an omitted upper bound should still be the
"infinity" of the index type, so it is a bug when the documentation says
its maxint. However, it is also a bug that the index type is int, as it
should rather be size_t (more precisely, ssize_t). Unfortunately, long
and ssize_t are also of different widths on some platforms.

So I think there should be a sys.maxindex, which is the maximum value
for ssize_t, and that should be the implicit upper bound for getslice,
and the documentation should be fixed accordingly.

For 2.4.x, it is *just* that the documentation should be fixed; the
code needs to stay as it is even though there is no convenient way
to get at the maximum index. Just trying one time at startup would
be the recommended way:

class _GetMaxIndex:
def __getslice__(self, a, mi):
import sys
sys.maxindex = mi
_GetMaxIndex()[:]

Regards,
Martin
Jul 18 '05 #2

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

Similar topics

0
1300
by: Bengt Richter | last post by:
Peculiar boundary cases: >>> 2.0**31-1.0 2147483647.0 >>> int(2147483647.0) 2147483647L >>> int(2147483647L ) 2147483647 >>> >>> -2.0**31
6
2058
by: Bengt Richter | last post by:
Peculiar boundary cases: >>> 2.0**31-1.0 2147483647.0 >>> int(2147483647.0) 2147483647L >>> int(2147483647L ) 2147483647 >>> >>> -2.0**31
18
2710
by: Fernando Perez | last post by:
Hi all, I was wondering if someone can help me understand why __getslice__ has been deprecated, yet it remains necessary to implement it for simple slices (i:j), while __getitem__ gets called...
11
12484
by: Marc Ferry | last post by:
I already posted this mail in comp.sys.hp and comp.sys.hp.hpux but had no response. As this problem might be present on other OSes than HP-UX 10.20, I crosspost it here, in the hope of getting an...
0
1541
by: KIM | last post by:
Hi! We are trying to realize message-based security with WCF June CTP. We get the messages encrypted but not signed (see SOAP-message below)! We also tried the "Message Security Sample" from the...
24
4121
by: Yevgen Muntyan | last post by:
Hey, Is it correct that number of value bits in int and unsigned int representation may be the same? If it is so, then INT_MIN may be -(INT_MAX+1) (in mathematical sense), i.e. abs(INT_MIN) is...
5
1935
by: Torsten Bronger | last post by:
Hallöchen! According to <http://docs.python.org/ref/sequence-methods.html>, __getslice__ is deprecated. At the moment, I derive an own class from unicode and want to implement my own slicing. ...
4
9313
by: bearophileHUGS | last post by:
In some algorithms a sentinel value may be useful, so for Python 3.x sys.maxint may be replaced by an improvement of the following infinite and neginfinite singleton objects: class...
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7181
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
5442
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
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.