[Python-checkins] r78505 - in python/branches/py3k: Lib/test/test_metaclass.py Misc/NEWS Python/bltinmodule.c
benjamin.peterson
python-checkins at python.org
Sat Feb 27 18:40:02 CET 2010
Author: benjamin.peterson
Date: Sat Feb 27 18:40:01 2010
New Revision: 78505
Log:
only accept AttributeError as indicating no __prepare__ attribute on a metaclass, allowing lookup errors to propogate
Modified:
python/branches/py3k/Lib/test/test_metaclass.py
python/branches/py3k/Misc/NEWS
python/branches/py3k/Python/bltinmodule.c
Modified: python/branches/py3k/Lib/test/test_metaclass.py
==============================================================================
--- python/branches/py3k/Lib/test/test_metaclass.py (original)
+++ python/branches/py3k/Lib/test/test_metaclass.py Sat Feb 27 18:40:01 2010
@@ -230,6 +230,20 @@
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}
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Sat Feb 27 18:40:01 2010
@@ -12,6 +12,8 @@
Core and Builtins
-----------------
+- Handle errors from looking up __prepare__ correctly.
+
- Issue #5939: Add additional runtime checking to ensure a valid capsule
in Modules/_ctypes/callproc.c.
Modified: python/branches/py3k/Python/bltinmodule.c
==============================================================================
--- python/branches/py3k/Python/bltinmodule.c (original)
+++ python/branches/py3k/Python/bltinmodule.c Sat Feb 27 18:40:01 2010
@@ -108,8 +108,16 @@
}
prep = PyObject_GetAttrString(meta, "__prepare__");
if (prep == NULL) {
- PyErr_Clear();
- ns = PyDict_New();
+ if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ PyErr_Clear();
+ ns = PyDict_New();
+ }
+ else {
+ Py_DECREF(meta);
+ Py_XDECREF(mkw);
+ Py_DECREF(bases);
+ return NULL;
+ }
}
else {
PyObject *pargs = PyTuple_Pack(2, name, bases);
More information about the Python-checkins
mailing list