[Python-bugs-list] [ python-Bugs-443600 ] overload of the slicing operator

noreply@sourceforge.net noreply@sourceforge.net
Sat, 18 Aug 2001 10:44:31 -0700


Bugs item #443600, was opened at 2001-07-22 13:22
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=443600&group_id=5470

Category: Python Interpreter Core
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Markus Daniel (spacy73)
Assigned to: Guido van Rossum (gvanrossum)
Summary: overload of the slicing operator

Initial Comment:
It's impossible to overload the slicing operator
to take two float-values.


PythonWin 2.1 (#15, Apr 23 2001, 18:00:35) [MSC 32 bit 
(Intel)] on win32.
>>> class a:
... 	def __getitem__(self, index):
... 		print repr(index)
... 
>>> 
>>> aa=a()
>>> 
>>> aa[1.5]
1.5
>>> 
>>> aa[1.5:2.5]
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: slice indices must be integers
>>>
>>> aa[1.5:2.5:3.5]
slice(1.5, 2.5, 3.5)
>>> 

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-18 10:44

Message:
Logged In: YES 
user_id=6380

Turns out it wasn't so bad. :-)

Fixed in CVS, ceval.c:2.269.  This will be in 2.2a2.


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-06 19:41

Message:
Logged In: YES 
user_id=6380

It's complicated because the internal APIs are all busted, and "fixing" them might cause
backwards compatibilities, i.e. break existing 3rd party extensions.

This has been broken for a long time.  I agree that it ought to be fixed,
but not at the cost of backwards incompatibility, and I don't give it high priority.

Maybe we can define completely new C APIs that do this right
and then define the old ones just as b/w compatibility APIs.

But part of it is that we can't change the specs for calls into extension types,
because we don't know that the types would support the new rules.
This can be fixed by asking the types to specify some flag bit in their tp_flags field,
but it all gets very complicated -- for little gain, IMO.


----------------------------------------------------------------------

Comment By: Jeremy Hylton (jhylton)
Date: 2001-08-06 13:57

Message:
Logged In: YES 
user_id=31392

No idea what the right thing to do here.  BDFL?

You can do aa[slice(1.5, 2.5)], so I don't see why you
shouldn't be able to do aa[1.5:2.5].


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=443600&group_id=5470