[Patches] [ python-Patches-633870 ] allow any seq assignment to a list slice

noreply@sourceforge.net noreply@sourceforge.net
Tue, 05 Nov 2002 09:41:25 -0800


Patches item #633870, was opened at 2002-11-05 15:59
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=633870&group_id=5470

Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Alex Martelli (aleax)
Assigned to: Michael Hudson (mwh)
Summary: allow any seq assignment to a list slice

Initial Comment:
as suggested by Michael Hudson in his comp.lang.python 
post of Tue, 5 Nov 2002 14:03:46 GMT, Subject "Re: List 
slice assignment and custom sequences", message id 
<m2k7jsm7u7.fsf@python.net> .  The patch affects 
Objects/listobject.c: with no performance impact when the 
RHS of an assignment to a list slice is a list, the patch also 
allows the RHS to be any other sequence object acceptable 
to PySequence_Fast -- just like such general sequences are 
acceptable today e.g. as arguments to the extend method, 
so the patch makes them acceptable as RHS in assignment 
to list slices.



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

>Comment By: Michael Hudson (mwh)
Date: 2002-11-05 17:41

Message:
Logged In: YES 
user_id=6656

Looks OK to me.  Will check in when make test finishes.
...
It's in, as
Lib/test/test_types.py revision 1.38
Objects/listobject.c revision 2.138

feel free to write a better test case!

I'm a little concerned about docs, but can't find anything
that clearly defines the old behaviour (there's a little bit
in the lang ref, but that's talking about slice assignments
in general, not to lists).

PS: Alex, when submitted followup patches, please make it
obvious in the comment or the file name which is newest. 
I've suffered sf enough to remember that the top one is the
newest, but it's not that clear.  Yes, this is sf's fault,
but...

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-11-05 17:12

Message:
Logged In: YES 
user_id=6380

The idea sounds like a fine one to me. (I think that's a
reversal of opinion. So be it. :-)

I don't want to be responsible for reviewing the code
however. Assigned to MWH (since there's no way to simply
unassign).

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

Comment By: Alex Martelli (aleax)
Date: 2002-11-05 17:09

Message:
Logged In: YES 
user_id=60314

I cannot reliably measure any performance difference between 
using PySequence_Fast unconditionally, and specialcasing a list 
RHS.  I've attached the patch for the unconditional version, which 
is five lines less than the earlier specialcased version.


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

Comment By: Michael Hudson (mwh)
Date: 2002-11-05 16:51

Message:
Logged In: YES 
user_id=6656

I wonder if you'd get much performance hit from just using
PySequence_FAST the whole time?  All that does for a list
after all is Py_INCREF it (I hope you still have whatever
test harness you used to make your claims in the description).

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

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