Commit 23e018ab authored by Benjamin Peterson's avatar Benjamin Peterson

only accept AttributeError as indicating no __prepare__ attribute on a...

only accept AttributeError as indicating no __prepare__ attribute on a metaclass, allowing lookup errors to propogate
parent 8de42e2d
...@@ -230,6 +230,20 @@ Make sure it works with subclassing. ...@@ -230,6 +230,20 @@ Make sure it works with subclassing.
42 42
>>> >>>
Test failures in looking up the __prepare__ method work.
>>> class ObscureException(Exception):
... pass
>>> class FailDescr:
... def __get__(self, instance, owner):
... raise ObscureException
>>> class Meta(type):
... __prepare__ = FailDescr()
>>> class X(metaclass=Meta):
... pass
Traceback (most recent call last):
[...]
test.test_metaclass.ObscureException
""" """
__test__ = {'doctests' : doctests} __test__ = {'doctests' : doctests}
......
...@@ -12,6 +12,8 @@ What's New in Python 3.2 Alpha 1? ...@@ -12,6 +12,8 @@ What's New in Python 3.2 Alpha 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Handle errors from looking up __prepare__ correctly.
- Issue #5939: Add additional runtime checking to ensure a valid capsule - Issue #5939: Add additional runtime checking to ensure a valid capsule
in Modules/_ctypes/callproc.c. in Modules/_ctypes/callproc.c.
......
...@@ -108,9 +108,17 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) ...@@ -108,9 +108,17 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
} }
prep = PyObject_GetAttrString(meta, "__prepare__"); prep = PyObject_GetAttrString(meta, "__prepare__");
if (prep == NULL) { if (prep == NULL) {
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear(); PyErr_Clear();
ns = PyDict_New(); ns = PyDict_New();
} }
else {
Py_DECREF(meta);
Py_XDECREF(mkw);
Py_DECREF(bases);
return NULL;
}
}
else { else {
PyObject *pargs = PyTuple_Pack(2, name, bases); PyObject *pargs = PyTuple_Pack(2, name, bases);
if (pargs == NULL) { if (pargs == NULL) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment