Commit f32b1627 authored by Patrick Strawderman's avatar Patrick Strawderman

Raise an error when an invalid argument is passed to persistent.simple_new.

parent b2ec9b58
......@@ -1235,6 +1235,12 @@ Per_setstate(cPersistentObject *self)
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);
}
......
......@@ -462,7 +462,7 @@ that might be tedious.
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
......
......@@ -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 @@ def cpersistent_setstate_pointer_sanity():
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((
......
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