From 250ad613f3ae7e237e28d3a7a15a9b6fac16129f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Mon, 7 Apr 2008 05:43:42 +0000 Subject: [PATCH] Bug #2565: The repr() of type objects now calls them 'class', not 'type' - whether they are builtin types or not. --- Doc/library/stdtypes.rst | 2 +- Doc/tutorial/errors.rst | 2 +- Lib/ctypes/test/test_structures.py | 4 ++-- Lib/test/test_defaultdict.py | 2 +- Lib/test/test_descrtut.py | 10 ++++----- Lib/test/test_doctest3.txt | 2 +- Lib/test/test_generators.py | 34 +++++++++++++++--------------- Lib/test/test_genexps.py | 2 +- Lib/test/test_metaclass.py | 6 +++--- Lib/test/test_wsgiref.py | 2 +- Lib/test/test_xmlrpc.py | 4 ++-- Misc/NEWS | 3 +++ Objects/typeobject.c | 10 ++------- 13 files changed, 40 insertions(+), 43 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 52135984402..65408ce58c5 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2345,7 +2345,7 @@ by the built-in function :func:`type`. There are no special operations on types. The standard module :mod:`types` defines names for all standard built-in types. -Types are written like this: ````. +Types are written like this: ````. .. _bltin-null-object: diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 5c652a98714..cedffd5ba65 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -184,7 +184,7 @@ desired. :: ... print('x =', x) ... print('y =', y) ... - + ('spam', 'eggs') ('spam', 'eggs') x = spam diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py index c4eee86f1f9..3587f0f11df 100644 --- a/Lib/ctypes/test/test_structures.py +++ b/Lib/ctypes/test/test_structures.py @@ -307,14 +307,14 @@ class StructureTestCase(unittest.TestCase): cls, msg = self.get_except(Person, "Someone", (1, 2)) self.failUnlessEqual(cls, RuntimeError) self.failUnlessEqual(msg, - "(Phone) : " + "(Phone) : " "expected string, int found") cls, msg = self.get_except(Person, "Someone", ("a", "b", "c")) self.failUnlessEqual(cls, RuntimeError) if issubclass(Exception, object): self.failUnlessEqual(msg, - "(Phone) : too many initializers") + "(Phone) : too many initializers") else: self.failUnlessEqual(msg, "(Phone) TypeError: too many initializers") diff --git a/Lib/test/test_defaultdict.py b/Lib/test/test_defaultdict.py index 6eb25adc289..065cc102030 100644 --- a/Lib/test/test_defaultdict.py +++ b/Lib/test/test_defaultdict.py @@ -64,7 +64,7 @@ class TestDefaultDict(unittest.TestCase): d2 = defaultdict(int) self.assertEqual(d2.default_factory, int) d2[12] = 42 - self.assertEqual(repr(d2), "defaultdict(, {12: 42})") + self.assertEqual(repr(d2), "defaultdict(, {12: 42})") def foo(): return 43 d3 = defaultdict(foo) self.assert_(d3.default_factory is foo) diff --git a/Lib/test/test_descrtut.py b/Lib/test/test_descrtut.py index 4933c9f5b8a..1ddab0e5463 100644 --- a/Lib/test/test_descrtut.py +++ b/Lib/test/test_descrtut.py @@ -39,7 +39,7 @@ Here's the new type at work: >>> print(defaultdict) # show our type >>> print(type(defaultdict)) # its metatype - + >>> a = defaultdict(default=0.0) # create an instance >>> print(a) # show the instance {} @@ -149,11 +149,11 @@ Introspecting instances of built-in types For instance of built-in types, x.__class__ is now the same as type(x): >>> type([]) - + >>> [].__class__ - + >>> list - + >>> isinstance([], list) True >>> isinstance([], dict) @@ -346,7 +346,7 @@ Hmm -- property is builtin now, so let's try it that way too. >>> del property # unmask the builtin >>> property - + >>> class C(object): ... def __init__(self): diff --git a/Lib/test/test_doctest3.txt b/Lib/test/test_doctest3.txt index 54a96d58e14..dd8557e57a5 100644 --- a/Lib/test/test_doctest3.txt +++ b/Lib/test/test_doctest3.txt @@ -2,4 +2,4 @@ Here we check that `__file__` is provided: >>> type(__file__) - + diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 04f13590dfd..992126ff05d 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -377,10 +377,10 @@ From the Iterators list, about the types of these things. ... yield 1 ... >>> type(g) - + >>> i = g() >>> type(i) - + >>> [s for s in dir(i) if not s.startswith('_')] ['close', 'gi_code', 'gi_frame', 'gi_running', 'send', 'throw'] >>> print(i.__next__.__doc__) @@ -396,7 +396,7 @@ And more, added later. >>> i.gi_running 0 >>> type(i.gi_frame) - + >>> i.gi_running = 42 Traceback (most recent call last): ... @@ -794,27 +794,27 @@ These are fine: >>> def f(): ... yield >>> type(f()) - + >>> def f(): ... if 0: ... yield >>> type(f()) - + >>> def f(): ... if 0: ... yield 1 >>> type(f()) - + >>> def f(): ... if "": ... yield None >>> type(f()) - + >>> def f(): ... return @@ -838,7 +838,7 @@ These are fine: ... x = 1 ... return >>> type(f()) - + >>> def f(): ... if 0: @@ -846,7 +846,7 @@ These are fine: ... yield 1 ... >>> type(f()) - + >>> def f(): ... if 0: @@ -856,7 +856,7 @@ These are fine: ... def f(self): ... yield 2 >>> type(f()) - + >>> def f(): ... if 0: @@ -864,7 +864,7 @@ These are fine: ... if 0: ... yield 2 >>> type(f()) - + >>> def f(): @@ -1512,7 +1512,7 @@ And a more sane, but still weird usage: >>> def f(): list(i for i in [(yield 26)]) >>> type(f()) - + A yield expression with augmented assignment. @@ -1749,25 +1749,25 @@ enclosing function a generator: >>> def f(): x += yield >>> type(f()) - + >>> def f(): x = yield >>> type(f()) - + >>> def f(): lambda x=(yield): 1 >>> type(f()) - + >>> def f(): x=(i for i in (yield) if (yield)) >>> type(f()) - + >>> def f(d): d[(yield "a")] = d[(yield "b")] = 27 >>> data = [1,2] >>> g = f(data) >>> type(g) - + >>> g.send(None) 'a' >>> data diff --git a/Lib/test/test_genexps.py b/Lib/test/test_genexps.py index 6c60d02e78a..46f7ab88f35 100644 --- a/Lib/test/test_genexps.py +++ b/Lib/test/test_genexps.py @@ -27,7 +27,7 @@ Test first class >>> g = (i*i for i in range(4)) >>> type(g) - + >>> list(g) [0, 1, 4, 9] diff --git a/Lib/test/test_metaclass.py b/Lib/test/test_metaclass.py index abb33303285..733418ef955 100644 --- a/Lib/test/test_metaclass.py +++ b/Lib/test/test_metaclass.py @@ -78,7 +78,7 @@ Also pass another keyword. >>> class C(object, metaclass=M, other="haha"): ... pass ... - Prepare called: ('C', (,)) {'other': 'haha'} + Prepare called: ('C', (,)) {'other': 'haha'} New called: {'other': 'haha'} >>> C.__class__ is M True @@ -104,7 +104,7 @@ Use various combinations of explicit keywords and **kwds. >>> kwds = {'metaclass': M, 'other': 'haha'} >>> class C(*bases, **kwds): pass ... - Prepare called: ('C', (,)) {'other': 'haha'} + Prepare called: ('C', (,)) {'other': 'haha'} New called: {'other': 'haha'} >>> C.__class__ is M True @@ -114,7 +114,7 @@ Use various combinations of explicit keywords and **kwds. >>> kwds = {'other': 'haha'} >>> class C(B, metaclass=M, *bases, **kwds): pass ... - Prepare called: ('C', (, )) {'other': 'haha'} + Prepare called: ('C', (, )) {'other': 'haha'} New called: {'other': 'haha'} >>> C.__class__ is M True diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py index bcf6352063a..c02f0af8247 100755 --- a/Lib/test/test_wsgiref.py +++ b/Lib/test/test_wsgiref.py @@ -157,7 +157,7 @@ class IntegrationTests(TestCase): self.assertEqual( err.splitlines()[-2], "AssertionError: Headers (('Content-Type', 'text/plain')) must" - " be of type list: " + " be of type list: " ) diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index 0691f23847b..e708927e0e4 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -416,12 +416,12 @@ class SimpleServerTestCase(unittest.TestCase): result = multicall() # result.results contains; - # [{'faultCode': 1, 'faultString': ':' + # [{'faultCode': 1, 'faultString': ':' # 'method "this_is_not_exists" is not supported'>}] self.assertEqual(result.results[0]['faultCode'], 1) self.assertEqual(result.results[0]['faultString'], - ':method "this_is_not_exists" ' + ':method "this_is_not_exists" ' 'is not supported') except (xmlrpclib.ProtocolError, socket.error) as e: # ignore failures due to non-blocking socket 'unavailable' errors diff --git a/Misc/NEWS b/Misc/NEWS index 30d1d39b744..327c19939b5 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 3.0a5? Core and Builtins ----------------- +- Bug #2565: The repr() of type objects now calls them 'class', + not 'type' - whether they are builtin types or not. + - The command line processing was converted to pass Unicode strings through as unmodified as possible; as a consequence, the C API related to command line arguments was changed to use wchar_t. diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 7a6d258329b..e2e365e351d 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -600,7 +600,6 @@ static PyObject * type_repr(PyTypeObject *type) { PyObject *mod, *name, *rtn; - char *kind; mod = type_module(type, NULL); if (mod == NULL) @@ -613,15 +612,10 @@ type_repr(PyTypeObject *type) if (name == NULL) return NULL; - if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) - kind = "class"; - else - kind = "type"; - if (mod != NULL && PyUnicode_CompareWithASCIIString(mod, "builtins")) - rtn = PyUnicode_FromFormat("<%s '%U.%U'>", kind, mod, name); + rtn = PyUnicode_FromFormat("", mod, name); else - rtn = PyUnicode_FromFormat("<%s '%s'>", kind, type->tp_name); + rtn = PyUnicode_FromFormat("", type->tp_name); Py_XDECREF(mod); Py_DECREF(name);