From 205ba7d43e29c82580d75c302fee5c2632391da0 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 20 Apr 2010 15:26:45 -0400 Subject: 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 --- gi/pygi-argument.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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; -- cgit