mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
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.
This commit is contained in:
parent
596fc9c384
commit
b0aa98fd4f
4 changed files with 14 additions and 1 deletions
|
@ -135,6 +135,11 @@ from _ctypes import _SimpleCData
|
|||
|
||||
class py_object(_SimpleCData):
|
||||
_type_ = "O"
|
||||
def __repr__(self):
|
||||
try:
|
||||
return super(py_object, self).__repr__()
|
||||
except ValueError:
|
||||
return "%s(<NULL>)" % type(self).__name__
|
||||
|
||||
class c_short(_SimpleCData):
|
||||
_type_ = "h"
|
||||
|
|
|
@ -78,5 +78,10 @@ class PythonAPITestCase(unittest.TestCase):
|
|||
# not enough arguments
|
||||
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__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue