[Python-bugs-list] [ python-Bugs-573663 ] Type slice comparisons
noreply@sourceforge.net
noreply@sourceforge.net
Tue, 25 Jun 2002 11:25:33 -0700
Bugs item #573663, was opened at 2002-06-25 12:10
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=573663&group_id=5470
Category: Python Interpreter Core
Group: Python 2.2.1
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Thomas J. Duck (tomduck)
Assigned to: Nobody/Anonymous (nobody)
Summary: Type slice comparisons
Initial Comment:
There seems to be a problem in identifing an object of
type 'slice'. For example, the type of an integer
can be found:
>>> type(1)
<type 'int'>
and comparisons are correctly made:
>>> type(1)==int
1
However, although the type of a slice can be found:
>>> type(slice(0,0,0))
<type 'slice'>
comparisons don't work properly:
>>> type(slice(0,0,0))==slice
0
Strangely, the following operation does work:
>>> type(slice(0,0,0))==type(slice(1,1,1))
1
So, the behaviour for type 'slice' is at least inconsistent
with other types such as 'int'.
----------------------------------------------------------------------
>Comment By: Thomas J. Duck (tomduck)
Date: 2002-06-25 15:25
Message:
Logged In: YES
user_id=568469
Thanks for clearing this up for me, Raymond.
Cheers, Tom
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2002-06-25 15:07
Message:
Logged In: YES
user_id=80475
You're a little before your time ;)
In Python 2.2, slice() is a builtin function, which is, of
course, not equal to a slice object. What does work is:
type(slice(0,0,0)) == types.SliceType
In Python 2.3, slice() is now its own type constructor and
your comparision will work fine.
This is the documented behavior and not a bug.
Hopefully, the upgrade to Py2.3 will make more and more
intuitive behaviors work right out of the box :-)
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=573663&group_id=5470