Skip to content

Commit

Permalink
Merge pull request #57 from zopefoundation/py35-import-incompat
Browse files Browse the repository at this point in the history
Work around AttributeError raised by Python 3.5.x.
  • Loading branch information
tseaver committed Jan 24, 2017
2 parents f4531e4 + fb38ed5 commit 7c96119
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion BTrees/BTreeModuleTemplate.c
Expand Up @@ -558,8 +558,18 @@ module_init(void)
cPersistenceCAPI = (cPersistenceCAPIstruct *)PyCObject_Import(
"persistent.cPersistence", "CAPI");
#endif
if (cPersistenceCAPI == NULL)
if (cPersistenceCAPI == NULL) {
/* The Capsule API attempts to import 'persistent' and then
* walk down to the specified attribute using getattr. If the C
* extensions aren't available, this can result in an
* AttributeError being raised. Let that percolate up as an
* ImportError so it can be caught in the expected way.
*/
if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_ImportError)) {
PyErr_SetString(PyExc_ImportError, "persistent C extension unavailable");
}
return NULL;
}

#ifdef PY3K
#define _SET_TYPE(typ) ((PyObject*)(&typ))->ob_type = &PyType_Type
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -5,6 +5,10 @@
------------------

- Add support for Python 3.6.
- Raise an ``ImportError`` consistently on Python 3 if the C extension for
BTrees is used but the ``persistent`` C extension is not available.
Previously this could result in an odd ``AttributeError``. See
https://github.com/zopefoundation/BTrees/pull/55

4.4.0 (2017-01-11)
------------------
Expand Down

0 comments on commit 7c96119

Please sign in to comment.