[Patches] [Patch #101029] Call __getitem__ for slices when no __getslice__

noreply@sourceforge.net noreply@sourceforge.net
Tue, 15 Aug 2000 11:56:13 -0700


Patch #101029 has been updated. 

Project: 
Category: core (C code)
Status: Open
Summary: Call __getitem__ for slices when no __getslice__

Follow-Ups:

Date: 2000-Jul-31 06:55
By: twouters

Comment:
Call __getitem__ if no __getslice__ is available. similar for __delslice__ and __setslice__, and for the C API: calls mp_subscript() with a slice object of (start, end, None) if there is no sq_slice(), and the same for sq_ass_slice().

Eventually the reverse should be done, too: call __getslice__ instead of __getitem__ if the object has a __getslice__, and the 3rd argument to the slice is None: That way, we can ditch the 12 silly SLICE* opcodes, and always use slice objects. This *will* result in x[::] being passed to __getslice__ (if available) instead of __getitem__, however, so it is not 100% backwards compatible.

This patch is not terribly tested: I'm not feeling well, and I want to post this patch before I head off to home and dive back in bed ;) It doesn't crash, it survives 'make test', it survives manual testing, but it might leak.


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

Date: 2000-Jul-31 07:55
By: gvanrossum

Comment:
Looks cool to me, except that there's a lot of code duplication.

Maybe you can add a static helper routine to create a slice out of two ints to abstract.c and one that creates a 1-tuple containing such a slice to classobject.c.  (Trying to share code across .c files would require turning it into an official API which I think is overkill.)
-------------------------------------------------------

Date: 2000-Jul-31 14:35
By: twouters

Comment:
New version with less code duplication. Less, not none, unfortunately, because both abstract.c and classobject.c need roughly the same function :P Making the classobject.c one return a 1-tuple is not very useful, because only one place needs a 1-tuple, the other needs a 2-tuple, and I don't fancy modifying the 1-tuple separately.

Don't you wish C was more like Python ? *sigh*

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

Date: 2000-Aug-15 11:56
By: tim_one

Comment:
Assigned to Guido because his is the next natural voice in the conversation.

Thomas, note that this needs doc and test patches too if it's not to be Postponed.
-------------------------------------------------------

-------------------------------------------------------
For more info, visit:

http://sourceforge.net/patch/?func=detailpatch&patch_id=101029&group_id=5470