operator module isSequenceType with builtin set produces False

English, Mark Mark.English at rbccm.com
Tue Dec 18 07:15:12 EST 2007


X-Replace-Address:
mark.ignorethisbit.english at xxxrbccmxxx.ignorethisbittoo_and_removethosep
receding_xxxs_.com

This wasn't what I was expecting, so I thought I'd ask those more
knowledgeable, which is pretty much everybody.
Same result on Python 2.3.5 and Python 2.5.1 installed from python.org
binaries on Windows XP.

>>> try: set
>>> except NameError: from sets import Set as set
>>> class myset_fails(set): pass
>>> class myset_works(set):
>>>     def __getitem__(self): pass
>>> s = set()
>>> fails = myset_fails()
>>> works = myset_works()
>>> import operator
>>> operator.isSequenceType(s) #Not what I expected
False
>>> operator.isSequenceType(fails) #Not what I expected either
False
>>> operator.isSequenceType(works) #A hint at what isSequenceType does ?
True

Are sets not sequences ? I didn't think the isSequenceDisclaimer gave
false negatives.
See Raymond Hettinger's post here too:
http://groups.google.co.uk/group/comp.lang.python/tree/browse_frm/thread
/bd04db20cc1f23bb/36f1f48bb7be1e4b?hl=en&rnum=1&q=set+isSequenceType&_do
ne=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2Fbd04db20cc1f23bb%
2F0454f5debc01c20d%3Fhl%3Den%26lnk%3Dgst%26q%3Dset%2BisSequenceType%26#d
oc_0454f5debc01c20d

Although there are suggestions that it means simply that you're headed
in the wrong direction design wise:
http://www.mail-archive.com/python-dev@python.org/msg11576.html

but then why have isSequenceType at all ?


Not particularly vital. Just implementing __str__ on some class and if
one of the members was a sequence
I was going to format that bit of data in brackets.

Thanks,
Mark

______________________________________________________________________

This email is intended only for the use of the individual(s) to whom it is addressed and may be privileged and confidential.
Unauthorised use or disclosure is prohibited.If you receive This e-mail in error, please advise immediately and delete the original message.
This message may have been altered without your or our knowledge and the sender does not accept any liability for any errors or omissions in the message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071218/405a9737/attachment.html>


More information about the Python-list mailing list