[Zodb-checkins] SVN: ZODB/trunk/src/persistent/ Raise an error when an invalid argument is passed to persistent.simple_new.
Patrick Strawderman
patrick at zope.com
Wed Apr 7 13:22:17 EDT 2010
Log message for revision 110603:
Raise an error when an invalid argument is passed to persistent.simple_new.
Changed:
U ZODB/trunk/src/persistent/cPersistence.c
U ZODB/trunk/src/persistent/tests/persistent.txt
U ZODB/trunk/src/persistent/tests/test_persistent.py
-=-
Modified: ZODB/trunk/src/persistent/cPersistence.c
===================================================================
--- ZODB/trunk/src/persistent/cPersistence.c 2010-04-07 16:39:36 UTC (rev 110602)
+++ ZODB/trunk/src/persistent/cPersistence.c 2010-04-07 17:22:16 UTC (rev 110603)
@@ -1235,6 +1235,12 @@
static PyObject *
simple_new(PyObject *self, PyObject *type_object)
{
+ if (!PyType_Check(type_object))
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "simple_new argument must be a type object.");
+ return NULL;
+ }
return PyType_GenericNew((PyTypeObject *)type_object, NULL, NULL);
}
Modified: ZODB/trunk/src/persistent/tests/persistent.txt
===================================================================
--- ZODB/trunk/src/persistent/tests/persistent.txt 2010-04-07 16:39:36 UTC (rev 110602)
+++ ZODB/trunk/src/persistent/tests/persistent.txt 2010-04-07 17:22:16 UTC (rev 110603)
@@ -462,7 +462,7 @@
Interfaces
----------
-Some versions of Zope and ZODB have the `zope.interfaces` package available.
+Some versions of Zope and ZODB have the `zope.interface` package available.
If it is available, then persistent will be associated with several
interfaces. It's hard to write a doctest test that runs the tests only if
`zope.interface` is available, so this test looks a little unusual. One
Modified: ZODB/trunk/src/persistent/tests/test_persistent.py
===================================================================
--- ZODB/trunk/src/persistent/tests/test_persistent.py 2010-04-07 16:39:36 UTC (rev 110602)
+++ ZODB/trunk/src/persistent/tests/test_persistent.py 2010-04-07 17:22:16 UTC (rev 110603)
@@ -13,7 +13,7 @@
##############################################################################
import unittest
from zope.testing import doctest
-from persistent import Persistent
+from persistent import Persistent, simple_new
class P(Persistent):
def __init__(self):
@@ -35,6 +35,13 @@
TypeError: this object has no instance dictionary
"""
+def cpersistent_simple_new_invalid_argument():
+ """
+ >>> simple_new('')
+ Traceback (most recent call last):
+ ...
+ TypeError: simple_new argument must be a type object.
+ """
def test_suite():
return unittest.TestSuite((
More information about the Zodb-checkins
mailing list