Fix construction from dict for std::multimap std::unordered_multimap (Python 3)

This commit is contained in:
William S Fulton 2017-06-23 14:38:26 +01:00
commit 005ff93dbd
2 changed files with 10 additions and 2 deletions

View file

@ -23,7 +23,11 @@
int res = SWIG_ERROR;
if (PyDict_Check(obj)) {
SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL);
return traits_asptr_stdseq<std::multimap<K,T>, std::pair<K, T> >::asptr(items, val);
%#if PY_VERSION_HEX >= 0x03000000
/* In Python 3.x the ".items()" method returns a dict_items object */
items = PySequence_Fast(items, ".items() didn't return a sequence!");
%#endif
res = traits_asptr_stdseq<std::multimap<K,T>, std::pair<K, T> >::asptr(items, val);
} else {
multimap_type *p;
swig_type_info *descriptor = swig::type_info<multimap_type>();

View file

@ -30,7 +30,11 @@
int res = SWIG_ERROR;
if (PyDict_Check(obj)) {
SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL);
return traits_asptr_stdseq<std::unordered_multimap<K,T>, std::pair<K, T> >::asptr(items, val);
%#if PY_VERSION_HEX >= 0x03000000
/* In Python 3.x the ".items()" method returns a dict_items object */
items = PySequence_Fast(items, ".items() didn't return a sequence!");
%#endif
res = traits_asptr_stdseq<std::unordered_multimap<K,T>, std::pair<K, T> >::asptr(items, val);
} else {
unordered_multimap_type *p;
swig_type_info *descriptor = swig::type_info<unordered_multimap_type>();