From: Raymond Hettinger Date: Wed, 7 Feb 2007 22:24:07 +0000 (+0000) Subject: Bug #1575169: operator.isSequenceType() now returns False for subclasses of dict. X-Git-Tag: v2.6a1~2201 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4da5bf644ab0aa836d29d076524c49cd9b6f3c03;p=python Bug #1575169: operator.isSequenceType() now returns False for subclasses of dict. --- diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py index c1fe88cbef..3cc0f1e837 100644 --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -215,6 +215,8 @@ class OperatorTestCase(unittest.TestCase): self.failUnless(operator.isSequenceType(xrange(10))) self.failUnless(operator.isSequenceType('yeahbuddy')) self.failIf(operator.isSequenceType(3)) + class Dict(dict): pass + self.failIf(operator.isSequenceType(Dict())) def test_lshift(self): self.failUnlessRaises(TypeError, operator.lshift) diff --git a/Objects/abstract.c b/Objects/abstract.c index 7115c523c2..7462c58dec 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1157,6 +1157,8 @@ PySequence_Check(PyObject *s) { if (s && PyInstance_Check(s)) return PyObject_HasAttrString(s, "__getitem__"); + if (PyObject_IsInstance(s, &PyDict_Type)) + return 0; return s != NULL && s->ob_type->tp_as_sequence && s->ob_type->tp_as_sequence->sq_item != NULL; }