Commit 5a7bf5fb authored by Thomas Heller's avatar Thomas Heller

The __repr__ method of a NULL py_object does no longer raise an

exception.  Remove a stray '?' character from the exception text
when the value is retrieved of such an object.

Includes tests.
parent 726b5dc3
...@@ -135,6 +135,11 @@ from _ctypes import _SimpleCData ...@@ -135,6 +135,11 @@ from _ctypes import _SimpleCData
class py_object(_SimpleCData): class py_object(_SimpleCData):
_type_ = "O" _type_ = "O"
def __repr__(self):
try:
return super(py_object, self).__repr__()
except ValueError:
return "%s(<NULL>)" % type(self).__name__
class c_short(_SimpleCData): class c_short(_SimpleCData):
_type_ = "h" _type_ = "h"
......
...@@ -78,5 +78,10 @@ class PythonAPITestCase(unittest.TestCase): ...@@ -78,5 +78,10 @@ class PythonAPITestCase(unittest.TestCase):
# not enough arguments # not enough arguments
self.failUnlessRaises(TypeError, PyOS_snprintf, buf) self.failUnlessRaises(TypeError, PyOS_snprintf, buf)
def test_pyobject_repr(self):
self.failUnlessEqual(repr(py_object()), "py_object(<NULL>)")
self.failUnlessEqual(repr(py_object(42)), "py_object(42)")
self.failUnlessEqual(repr(py_object(object)), "py_object(%r)" % object)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -64,6 +64,9 @@ Core and builtins ...@@ -64,6 +64,9 @@ Core and builtins
Library Library
------- -------
- The __repr__ method a NULL ctypes.py_object() does no longer raise
an exception.
- uuid.UUID now has a bytes_le attribute. This returns the UUID in - uuid.UUID now has a bytes_le attribute. This returns the UUID in
little-endian byte order for Windows. In addition, uuid.py had some little-endian byte order for Windows. In addition, uuid.py had some
workarounds for clocks with low resolution, to stop the code yielding workarounds for clocks with low resolution, to stop the code yielding
......
...@@ -1100,7 +1100,7 @@ O_get(void *ptr, unsigned size) ...@@ -1100,7 +1100,7 @@ O_get(void *ptr, unsigned size)
if (!PyErr_Occurred()) if (!PyErr_Occurred())
/* Set an error if not yet set */ /* Set an error if not yet set */
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"PyObject is NULL?"); "PyObject is NULL");
return NULL; return NULL;
} }
Py_INCREF(ob); Py_INCREF(ob);
......
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