summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-04-04 08:51:41 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-04-04 08:51:41 (GMT)
commite2eda606a83cbe68846faf44b478053e250fb025 (patch)
treeb9241a4342bc1111b71e173ac0c3c284dc1cda10 /Objects/abstract.c
parentd12dfbbcd90286067bc76b53fd48aedd3efbfdd2 (diff)
downloadcpython-e2eda606a83cbe68846faf44b478053e250fb025.zip
cpython-e2eda606a83cbe68846faf44b478053e250fb025.tar.gz
cpython-e2eda606a83cbe68846faf44b478053e250fb025.tar.bz2
Improve accuracy of sequence and mapping checks.
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index bf60c75..307ef86 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1058,6 +1058,8 @@ PyNumber_Float(PyObject *o)
int
PySequence_Check(PyObject *s)
{
+ if (PyInstance_Check(s))
+ return PyObject_HasAttrString(s, "__getitem__");
return s != NULL && s->ob_type->tp_as_sequence &&
s->ob_type->tp_as_sequence->sq_item != NULL;
}
@@ -1600,8 +1602,12 @@ PySequence_Index(PyObject *s, PyObject *o)
int
PyMapping_Check(PyObject *o)
{
- return o && o->ob_type->tp_as_mapping &&
- o->ob_type->tp_as_mapping->mp_subscript;
+ if (PyInstance_Check(o))
+ return PyObject_HasAttrString(o, "__getitem__");
+
+ return o && o->ob_type->tp_as_mapping &&
+ o->ob_type->tp_as_mapping->mp_subscript &&
+ !PyObject_HasAttrString(o, "__getslice__");
}
int