Skip to content

Commit

Permalink
Bug python#2565: The repr() of type objects now calls them 'class',
Browse files Browse the repository at this point in the history
not 'type' - whether they are builtin types or not.
  • Loading branch information
loewis committed Apr 7, 2008
1 parent 5a6f458 commit 250ad61
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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: ``<type 'int'>``.
Types are written like this: ``<class 'int'>``.


.. _bltin-null-object:
Expand Down
2 changes: 1 addition & 1 deletion Doc/tutorial/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ desired. ::
... print('x =', x)
... print('y =', y)
...
<type 'Exception'>
<class 'Exception'>
('spam', 'eggs')
('spam', 'eggs')
x = spam
Expand Down
4 changes: 2 additions & 2 deletions Lib/ctypes/test/test_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ class Person(Structure):
cls, msg = self.get_except(Person, "Someone", (1, 2))
self.failUnlessEqual(cls, RuntimeError)
self.failUnlessEqual(msg,
"(Phone) <type 'TypeError'>: "
"(Phone) <class 'TypeError'>: "
"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) <type 'TypeError'>: too many initializers")
"(Phone) <class 'TypeError'>: too many initializers")
else:
self.failUnlessEqual(msg, "(Phone) TypeError: too many initializers")

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_defaultdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_repr(self):
d2 = defaultdict(int)
self.assertEqual(d2.default_factory, int)
d2[12] = 42
self.assertEqual(repr(d2), "defaultdict(<type 'int'>, {12: 42})")
self.assertEqual(repr(d2), "defaultdict(<class 'int'>, {12: 42})")
def foo(): return 43
d3 = defaultdict(foo)
self.assert_(d3.default_factory is foo)
Expand Down
10 changes: 5 additions & 5 deletions Lib/test/test_descrtut.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def merge(self, other):
>>> print(defaultdict) # show our type
<class 'test.test_descrtut.defaultdict'>
>>> print(type(defaultdict)) # its metatype
<type 'type'>
<class 'type'>
>>> a = defaultdict(default=0.0) # create an instance
>>> print(a) # show the instance
{}
Expand Down Expand Up @@ -149,11 +149,11 @@ def merge(self, other):
For instance of built-in types, x.__class__ is now the same as type(x):
>>> type([])
<type 'list'>
<class 'list'>
>>> [].__class__
<type 'list'>
<class 'list'>
>>> list
<type 'list'>
<class 'list'>
>>> isinstance([], list)
True
>>> isinstance([], dict)
Expand Down Expand Up @@ -346,7 +346,7 @@ class passed as the first argument of foo() is the class involved in the
>>> del property # unmask the builtin
>>> property
<type 'property'>
<class 'property'>
>>> class C(object):
... def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_doctest3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Here we check that `__file__` is provided:

>>> type(__file__)
<type 'str'>
<class 'str'>
34 changes: 17 additions & 17 deletions Lib/test/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@
... yield 1
...
>>> type(g)
<type 'function'>
<class 'function'>
>>> i = g()
>>> type(i)
<type 'generator'>
<class 'generator'>
>>> [s for s in dir(i) if not s.startswith('_')]
['close', 'gi_code', 'gi_frame', 'gi_running', 'send', 'throw']
>>> print(i.__next__.__doc__)
Expand All @@ -396,7 +396,7 @@
>>> i.gi_running
0
>>> type(i.gi_frame)
<type 'frame'>
<class 'frame'>
>>> i.gi_running = 42
Traceback (most recent call last):
...
Expand Down Expand Up @@ -794,27 +794,27 @@
>>> def f():
... yield
>>> type(f())
<type 'generator'>
<class 'generator'>
>>> def f():
... if 0:
... yield
>>> type(f())
<type 'generator'>
<class 'generator'>
>>> def f():
... if 0:
... yield 1
>>> type(f())
<type 'generator'>
<class 'generator'>
>>> def f():
... if "":
... yield None
>>> type(f())
<type 'generator'>
<class 'generator'>
>>> def f():
... return
Expand All @@ -838,15 +838,15 @@
... x = 1
... return
>>> type(f())
<type 'generator'>
<class 'generator'>
>>> def f():
... if 0:
... def g():
... yield 1
...
>>> type(f())
<type 'NoneType'>
<class 'NoneType'>
>>> def f():
... if 0:
Expand All @@ -856,15 +856,15 @@
... def f(self):
... yield 2
>>> type(f())
<type 'NoneType'>
<class 'NoneType'>
>>> def f():
... if 0:
... return
... if 0:
... yield 2
>>> type(f())
<type 'generator'>
<class 'generator'>
>>> def f():
Expand Down Expand Up @@ -1512,7 +1512,7 @@ def printsolution(self, x):
>>> def f(): list(i for i in [(yield 26)])
>>> type(f())
<type 'generator'>
<class 'generator'>
A yield expression with augmented assignment.
Expand Down Expand Up @@ -1749,25 +1749,25 @@ def printsolution(self, x):
>>> def f(): x += yield
>>> type(f())
<type 'generator'>
<class 'generator'>
>>> def f(): x = yield
>>> type(f())
<type 'generator'>
<class 'generator'>
>>> def f(): lambda x=(yield): 1
>>> type(f())
<type 'generator'>
<class 'generator'>
>>> def f(): x=(i for i in (yield) if (yield))
>>> type(f())
<type 'generator'>
<class 'generator'>
>>> def f(d): d[(yield "a")] = d[(yield "b")] = 27
>>> data = [1,2]
>>> g = f(data)
>>> type(g)
<type 'generator'>
<class 'generator'>
>>> g.send(None)
'a'
>>> data
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_genexps.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
>>> g = (i*i for i in range(4))
>>> type(g)
<type 'generator'>
<class 'generator'>
>>> list(g)
[0, 1, 4, 9]
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_metaclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
>>> class C(object, metaclass=M, other="haha"):
... pass
...
Prepare called: ('C', (<type 'object'>,)) {'other': 'haha'}
Prepare called: ('C', (<class 'object'>,)) {'other': 'haha'}
New called: {'other': 'haha'}
>>> C.__class__ is M
True
Expand All @@ -104,7 +104,7 @@
>>> kwds = {'metaclass': M, 'other': 'haha'}
>>> class C(*bases, **kwds): pass
...
Prepare called: ('C', (<type 'object'>,)) {'other': 'haha'}
Prepare called: ('C', (<class 'object'>,)) {'other': 'haha'}
New called: {'other': 'haha'}
>>> C.__class__ is M
True
Expand All @@ -114,7 +114,7 @@
>>> kwds = {'other': 'haha'}
>>> class C(B, metaclass=M, *bases, **kwds): pass
...
Prepare called: ('C', (<class 'test.test_metaclass.B'>, <type 'object'>)) {'other': 'haha'}
Prepare called: ('C', (<class 'test.test_metaclass.B'>, <class 'object'>)) {'other': 'haha'}
New called: {'other': 'haha'}
>>> C.__class__ is M
True
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_wsgiref.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def bad_app(environ,start_response):
self.assertEqual(
err.splitlines()[-2],
"AssertionError: Headers (('Content-Type', 'text/plain')) must"
" be of type list: <type 'tuple'>"
" be of type list: <class 'tuple'>"
)


Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,12 @@ def test_non_existing_multicall(self):
result = multicall()

# result.results contains;
# [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:'
# [{'faultCode': 1, 'faultString': '<class \'exceptions.Exception\'>:'
# 'method "this_is_not_exists" is not supported'>}]

self.assertEqual(result.results[0]['faultCode'], 1)
self.assertEqual(result.results[0]['faultString'],
'<type \'Exception\'>:method "this_is_not_exists" '
'<class \'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
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 2 additions & 8 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ static PyObject *
type_repr(PyTypeObject *type)
{
PyObject *mod, *name, *rtn;
char *kind;

mod = type_module(type, NULL);
if (mod == NULL)
Expand All @@ -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("<class '%U.%U'>", mod, name);
else
rtn = PyUnicode_FromFormat("<%s '%s'>", kind, type->tp_name);
rtn = PyUnicode_FromFormat("<class '%s'>", type->tp_name);

Py_XDECREF(mod);
Py_DECREF(name);
Expand Down

0 comments on commit 250ad61

Please sign in to comment.