diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py --- a/Lib/ctypes/test/test_structures.py +++ b/Lib/ctypes/test/test_structures.py @@ -315,16 +315,11 @@ class StructureTestCase(unittest.TestCas cls, msg = self.get_except(Person, b"Someone", (1, 2)) self.assertEqual(cls, RuntimeError) self.assertEqual(msg, - "(Phone) : " - "expected string, int found") + '(Phone) TypeError: expected string, int found') cls, msg = self.get_except(Person, b"Someone", (b"a", b"b", b"c")) self.assertEqual(cls, RuntimeError) - if issubclass(Exception, object): - self.assertEqual(msg, - "(Phone) : too many initializers") - else: - self.assertEqual(msg, "(Phone) TypeError: too many initializers") + self.assertEqual(msg, "(Phone) TypeError: too many initializers") def test_huge_field_name(self): # issue12881: segfault with large structure field names diff --git a/Lib/optparse.py b/Lib/optparse.py --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -674,7 +674,7 @@ class Option: elif not isinstance(self.choices, (tuple, list)): raise OptionError( "choices must be a list of strings ('%s' supplied)" - % str(type(self.choices)).split("'")[1], self) + % type(self.choices), self) elif self.choices is not None: raise OptionError( "must not supply choices for type %r" % self.type, self) diff --git a/Lib/test/test_descrtut.py b/Lib/test/test_descrtut.py --- a/Lib/test/test_descrtut.py +++ b/Lib/test/test_descrtut.py @@ -37,16 +37,16 @@ test_1 = """ Here's the new type at work: >>> print(defaultdict) # show our type - + test.test_descrtut.defaultdict >>> print(type(defaultdict)) # its metatype - + type >>> a = defaultdict(default=0.0) # create an instance >>> print(a) # show the instance {} >>> print(type(a)) # show its type - + test.test_descrtut.defaultdict >>> print(a.__class__) # show its class - + test.test_descrtut.defaultdict >>> print(type(a) is a.__class__) # its type is its class True >>> a[1] = 3.25 # modify the instance @@ -258,19 +258,19 @@ implicit first argument that is the *cla ... print("classmethod", cls, y) >>> C.foo(1) - classmethod 1 + classmethod test.test_descrtut.C 1 >>> c = C() >>> c.foo(1) - classmethod 1 + classmethod test.test_descrtut.C 1 >>> class D(C): ... pass >>> D.foo(1) - classmethod 1 + classmethod test.test_descrtut.D 1 >>> d = D() >>> d.foo(1) - classmethod 1 + classmethod test.test_descrtut.D 1 This prints "classmethod __main__.D 1" both times; in other words, the class passed as the first argument of foo() is the class involved in the @@ -286,11 +286,11 @@ But notice this: >>> E.foo(1) E.foo() called - classmethod 1 + classmethod test.test_descrtut.C 1 >>> e = E() >>> e.foo(1) E.foo() called - classmethod 1 + classmethod test.test_descrtut.C 1 In this example, the call to C.foo() from E.foo() will see class C as its first argument, not class E. This is to be expected, since the call diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -566,8 +566,7 @@ class SimpleServerTestCase(BaseServerTes self.assertEqual(result.results[0]['faultCode'], 1) self.assertEqual(result.results[0]['faultString'], - ':method "this_is_not_exists" ' - 'is not supported') + 'Exception:method "this_is_not_exists" is not supported') except (xmlrpclib.ProtocolError, socket.error) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -667,6 +667,32 @@ type_repr(PyTypeObject *type) } static PyObject * +type_str(PyTypeObject *type) +{ + PyObject *mod, *name, *rtn; + + mod = type_module(type, NULL); + if (mod == NULL) + PyErr_Clear(); + else if (!PyUnicode_Check(mod)) { + Py_DECREF(mod); + mod = NULL; + } + name = type_name(type, NULL); + if (name == NULL) + return NULL; + + if (mod != NULL && PyUnicode_CompareWithASCIIString(mod, "builtins")) + rtn = PyUnicode_FromFormat("%U.%U", mod, name); + else + rtn = PyUnicode_FromFormat("%s", type->tp_name); + + Py_XDECREF(mod); + Py_DECREF(name); + return rtn; +} + +static PyObject * type_call(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *obj; @@ -2765,7 +2791,7 @@ PyTypeObject PyType_Type = { 0, /* tp_as_mapping */ 0, /* tp_hash */ (ternaryfunc)type_call, /* tp_call */ - 0, /* tp_str */ + (reprfunc)type_str, /* tp_str */ (getattrofunc)type_getattro, /* tp_getattro */ (setattrofunc)type_setattro, /* tp_setattro */ 0, /* tp_as_buffer */