[Python-bugs-list] [ python-Bugs-801349 ] New slice behaviour. Bug or feature?

SourceForge.net noreply at sourceforge.net
Mon Sep 15 13:42:07 EDT 2003


Bugs item #801349, was opened at 2003-09-05 21:28
Message generated for change (Comment added) made by mwh
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=801349&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: logistix (logistix)
Assigned to: Michael Hudson (mwh)
Summary: New slice behaviour.  Bug or feature?

Initial Comment:
Using a slice of x[:None] returns the whole list.  I would 

thing that if this sort of statement is valid, it should 

return an empty list, like x[:0].  In 2.2, you'll get an 

error with this statement.



This bit me when I was using None as a sentinel.



I'll be able to write a patch when I find out what the 

desired behaviour is (fine as-is, None should behave as 

0, it should throw an error, or other) assuming sf's cvs is 

playing nice.





Microsoft Windows XP [Version 5.1.2600]

(C) Copyright 1985-2001 Microsoft Corp.



C:\Documents and Settings\grant>c:\python23\python

Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 

32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more 

information.

>>> a = [1,2,3,4]

>>> a[:None]

[1, 2, 3, 4]

>>> ^Z





C:\Documents and Settings\grant>c:\python22\python

'import site' failed; use -v for traceback

Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit 

(Intel)] on win32

Type "help", "copyright", "credits" or "license" for more 

information.

>>> a = [1,2,3,4]

>>> a[:None]

Traceback (most recent call last):

  File "<stdin>", line 1, in ?

TypeError: sequence index must be integer

>>> ^Z





C:\Documents and Settings\grant>

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

>Comment By: Michael Hudson (mwh)
Date: 2003-09-15 18:42

Message:
Logged In: YES 
user_id=6656

I think passing a slice index of None should be equivalent to not 

passing any value at all.  Can you come up with a doc patch?

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

Comment By: logistix (logistix)
Date: 2003-09-06 22:53

Message:
Logged In: YES 
user_id=699438

Actually I now think this is behaving properly since slice uses 

None as sentinels.  'a[slice(None,None)]' is equivilent to a[:].  

Although 'a[None:None]' isn't a backward-compatible 

statement, it doesn't cause any forward compatibility issues 

with pre-2.3 code.  And changing the definition of 'None' on 

slice attributes would cause some serious breakage on third-

party packages.



However, if this is defined behaviour, I'll need to write some 

documentation patches.

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

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-09-06 02:31

Message:
Logged In: YES 
user_id=33168

Michael, do you think happened with your extended slice changes?

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

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



More information about the Python-bugs-list mailing list