summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2010-04-20 15:26:45 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2010-04-20 15:26:45 -0400
commit205ba7d43e29c82580d75c302fee5c2632391da0 (patch)
treea244c3bb2298f8abd3ef16bc488314426177c37b
parent3ae8ca093561c0abc36022290f52e41983600e5f (diff)
downloadpygi-205ba7d43e29c82580d75c302fee5c2632391da0.tar.gz
pygi-205ba7d43e29c82580d75c302fee5c2632391da0.tar.xz
pygi-205ba7d43e29c82580d75c302fee5c2632391da0.zip
Restrict GI_TYPE_TAG_GHASH on Python 3 to dicts, not mappings, due to http://bugs.python.org/issue5945
This fixes a failure in test_ghashtable_int_none_in (test_gi.TestGHashTable) where it would raise "AttributeError: keys" rather than a TypeError when invoked with a string
-rw-r--r--gi/pygi-argument.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index c6b62a0..8fbb837 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -532,7 +532,18 @@ check_number_release:
GITypeInfo *value_type_info;
Py_ssize_t i;
+#if PY_MAJOR_VERSION >= 3
+ /*
+ In Python 3, PyMapping_Check returns 1 for lists and strings
+ (this is http://bugs.python.org/issue5945), but PyMapping_Keys
+ fails with a "AttributeError: keys"
+
+ So for Python 3 we require the object to be a dictionary:
+ */
+ if (!PyDict_Check(object)) {
+#else
if (!PyMapping_Check(object)) {
+#endif
PyErr_Format(PyExc_TypeError, "Must be mapping, not %s",
object->ob_type->tp_name);
retval = 0;