[Patches] [ python-Patches-400998 ] experimental support for extended slicing on lists

noreply@sourceforge.net noreply@sourceforge.net
Fri, 07 Jun 2002 06:35:50 -0700


Patches item #400998, was opened at 2000-07-27 21:27
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=400998&group_id=5470

Category: Core (C code)
Group: None
Status: Open
Resolution: Accepted
Priority: 5
Submitted By: Michael Hudson (mwh)
Assigned to: Michael Hudson (mwh)
Summary: experimental support for extended slicing on lists

Initial Comment:
 

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

>Comment By: Michael Hudson (mwh)
Date: 2002-06-07 13:35

Message:
Logged In: YES 
user_id=6656

Hmm, I'm now older and more cowardly than when I wrote this,
and I have a couple of questions.

This patch changes the behaviour of PySlice_GetIndices,
which must count as a public API function (albeit a pretty
useless one as it is now).  Is that OK?  Or would it be
better to have a new function PySlice_GetIndicesEx or
something.  Should check whether NumPy uses this function.

Do you really want assignments to extended slices in lists?
 They were never that inuitive to me.

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-06-06 16:48

Message:
Logged In: YES 
user_id=6380

(I lied about array -- it is already a subclassable
new-style type. So go ahead, but do that one last.)

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-06-06 16:29

Message:
Logged In: YES 
user_id=6380

Go ahead and check it in.

Strings and unicode also need to support slices. While
"hello"[::2] is silly, it's useful to be able to write
"hello"[slice(1,-1)].

I think array needs more work -- first 'array.array' should
be made into a type object that can be invoked as a
constructor and subclassed. That would be nice, yes, but is
a lower priority for me ATM.

Off-topic aside: the change you had to make to
PyString_Format() and its Unicode cousin suggests that we
need a better way to decide if something is really a
mapping...  E.g. this now gives a confusing error message:
  "%(foo)s %(bar)s" % [1,2,3]
I wonder how many other places in the code make naive
mapping tests (and of course operator.isMappingType becomes
totally unreliable). Maybe the presence of a keys() method
together with a __getitem__ method should be used as a
standard test for mapping-ness?

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

Comment By: Michael Hudson (mwh)
Date: 2002-06-06 13:01

Message:
Logged In: YES 
user_id=6656

Whoosh, this is a blast from the past.

I've minimally updated the patch (it only failed to apply
for the trivialest of reasons).  All tests pass (I had to
tweak test_bool -- operator.isMappingType([]) is True now).

Suffice to say I don't really remember how this works :-/

What more needs to be done?  strings, arrays (shouldn't be
too hard).

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-06-03 21:00

Message:
Logged In: YES 
user_id=6380

Michael, the tide has changed.  Would you be interested in
reviving this patch and finishing it?

It could possibly help to address bug 473985 and maybe also
459235.

If you have no time, let me know and I'll see if I can find
time myself.


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

Comment By: Guido van Rossum (gvanrossum)
Date: 2000-12-18 22:19

Message:
Rejected for lack of interest.

Sorry, Michael!

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2000-11-13 19:45

Message:
Is reviewing and applying this patch the best use of my time? I note that this is okay, but low priority -- I doubt that it will get used much. Plus, what about the array module, strings, UserList?

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2000-09-01 02:10

Message:
Too late for the release, sorry. And Tim hates negative strides.

We'll get back to this for 2.1.

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

Comment By: Michael Hudson (mwh)
Date: 2000-08-16 19:30

Message:
So, I missed my deadline by twenty five minutes.  Sorry :-)

This latest patch adds a fairly basic test suite, a stab at some docs, and jumps up and down on PySlice_GetIndices.

Also (wrt. stringobject.c & unicodeobject.c) it's amazing what you can break, isn't it?  Thank God for test suites...

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

Comment By: Michael Hudson (mwh)
Date: 2000-08-16 19:30

Message:
So, I missed my deadline by twenty five minutes.  Sorry :-)

This latest patch adds a fairly basic test suite, a stab at some docs, and jumps up and down on PySlice_GetIndices.

Also (wrt. stringobject.c & unicodeobject.c) it's amazing what you can break, isn't it?  Thank God for test suites...

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

Comment By: Michael Hudson (mwh)
Date: 2000-08-15 19:04

Message:
OK, I'll get to that soon (ie. <24hours, hopefully <4).
But bear in mind I'm now going to the pub...

I may need some advice for the docs...


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

Comment By: Tim Peters (tim_one)
Date: 2000-08-15 18:53

Message:
Note that without doc and test patches too, and Real Soon, I'll have to Postpone this.  Assigned to me to remind me of that.

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

Comment By: Michael Hudson (mwh)
Date: 2000-07-30 18:41

Message:
meep!  naughty Michael hadn't been running "make test" often enough.
this update fixes that.

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

Comment By: Michael Hudson (mwh)
Date: 2000-07-30 18:10

Message:
bugfixes (refounting in assignment, logic in deletion) & a few tweaks.

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

Comment By: Michael Hudson (mwh)
Date: 2000-07-29 10:36

Message:
updated patch to support slice assignements, deletions
(needs testing still)

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

Comment By: Michael Hudson (mwh)
Date: 2000-07-28 06:47

Message:
negative indices!

for i in listvar[::-1]:
     pass

now iterates over the list backwards (rather than coredumping...)

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

Comment By: Michael Hudson (mwh)
Date: 2000-07-27 21:39

Message:
c'mon michael!  at least get *some* of the boundary cases...

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

Comment By: Michael Hudson (mwh)
Date: 2000-07-27 21:31

Message:
this 10 minute hack adds support for "extended slicing" to lists, by which I mean things like:

>>> range(100)[23:60:12]
[23, 35, 47, 59]

todo:
find out if this is the approved approach
add support for tuples
write docs, testsuite (make test passes as is, but should be extended).

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

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