Kaydet (Commit) 250ad613 authored tarafından Martin v. Löwis's avatar Martin v. Löwis

Bug #2565: The repr() of type objects now calls them 'class',

not 'type' - whether they are builtin types or not.
üst 5a6f4585
...@@ -2345,7 +2345,7 @@ by the built-in function :func:`type`. There are no special operations on ...@@ -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. The standard module :mod:`types` defines names for all standard built-in
types. types.
Types are written like this: ``<type 'int'>``. Types are written like this: ``<class 'int'>``.
.. _bltin-null-object: .. _bltin-null-object:
......
...@@ -184,7 +184,7 @@ desired. :: ...@@ -184,7 +184,7 @@ desired. ::
... print('x =', x) ... print('x =', x)
... print('y =', y) ... print('y =', y)
... ...
<type 'Exception'> <class 'Exception'>
('spam', 'eggs') ('spam', 'eggs')
('spam', 'eggs') ('spam', 'eggs')
x = spam x = spam
......
...@@ -307,14 +307,14 @@ class StructureTestCase(unittest.TestCase): ...@@ -307,14 +307,14 @@ class StructureTestCase(unittest.TestCase):
cls, msg = self.get_except(Person, "Someone", (1, 2)) cls, msg = self.get_except(Person, "Someone", (1, 2))
self.failUnlessEqual(cls, RuntimeError) self.failUnlessEqual(cls, RuntimeError)
self.failUnlessEqual(msg, self.failUnlessEqual(msg,
"(Phone) <type 'TypeError'>: " "(Phone) <class 'TypeError'>: "
"expected string, int found") "expected string, int found")
cls, msg = self.get_except(Person, "Someone", ("a", "b", "c")) cls, msg = self.get_except(Person, "Someone", ("a", "b", "c"))
self.failUnlessEqual(cls, RuntimeError) self.failUnlessEqual(cls, RuntimeError)
if issubclass(Exception, object): if issubclass(Exception, object):
self.failUnlessEqual(msg, self.failUnlessEqual(msg,
"(Phone) <type 'TypeError'>: too many initializers") "(Phone) <class 'TypeError'>: too many initializers")
else: else:
self.failUnlessEqual(msg, "(Phone) TypeError: too many initializers") self.failUnlessEqual(msg, "(Phone) TypeError: too many initializers")
......
...@@ -64,7 +64,7 @@ class TestDefaultDict(unittest.TestCase): ...@@ -64,7 +64,7 @@ class TestDefaultDict(unittest.TestCase):
d2 = defaultdict(int) d2 = defaultdict(int)
self.assertEqual(d2.default_factory, int) self.assertEqual(d2.default_factory, int)
d2[12] = 42 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 def foo(): return 43
d3 = defaultdict(foo) d3 = defaultdict(foo)
self.assert_(d3.default_factory is foo) self.assert_(d3.default_factory is foo)
......
...@@ -39,7 +39,7 @@ Here's the new type at work: ...@@ -39,7 +39,7 @@ Here's the new type at work:
>>> print(defaultdict) # show our type >>> print(defaultdict) # show our type
<class 'test.test_descrtut.defaultdict'> <class 'test.test_descrtut.defaultdict'>
>>> print(type(defaultdict)) # its metatype >>> print(type(defaultdict)) # its metatype
<type 'type'> <class 'type'>
>>> a = defaultdict(default=0.0) # create an instance >>> a = defaultdict(default=0.0) # create an instance
>>> print(a) # show the instance >>> print(a) # show the instance
{} {}
...@@ -149,11 +149,11 @@ Introspecting instances of built-in types ...@@ -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): For instance of built-in types, x.__class__ is now the same as type(x):
>>> type([]) >>> type([])
<type 'list'> <class 'list'>
>>> [].__class__ >>> [].__class__
<type 'list'> <class 'list'>
>>> list >>> list
<type 'list'> <class 'list'>
>>> isinstance([], list) >>> isinstance([], list)
True True
>>> isinstance([], dict) >>> isinstance([], dict)
...@@ -346,7 +346,7 @@ Hmm -- property is builtin now, so let's try it that way too. ...@@ -346,7 +346,7 @@ Hmm -- property is builtin now, so let's try it that way too.
>>> del property # unmask the builtin >>> del property # unmask the builtin
>>> property >>> property
<type 'property'> <class 'property'>
>>> class C(object): >>> class C(object):
... def __init__(self): ... def __init__(self):
......
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
Here we check that `__file__` is provided: Here we check that `__file__` is provided:
>>> type(__file__) >>> type(__file__)
<type 'str'> <class 'str'>
...@@ -377,10 +377,10 @@ From the Iterators list, about the types of these things. ...@@ -377,10 +377,10 @@ From the Iterators list, about the types of these things.
... yield 1 ... yield 1
... ...
>>> type(g) >>> type(g)
<type 'function'> <class 'function'>
>>> i = g() >>> i = g()
>>> type(i) >>> type(i)
<type 'generator'> <class 'generator'>
>>> [s for s in dir(i) if not s.startswith('_')] >>> [s for s in dir(i) if not s.startswith('_')]
['close', 'gi_code', 'gi_frame', 'gi_running', 'send', 'throw'] ['close', 'gi_code', 'gi_frame', 'gi_running', 'send', 'throw']
>>> print(i.__next__.__doc__) >>> print(i.__next__.__doc__)
...@@ -396,7 +396,7 @@ And more, added later. ...@@ -396,7 +396,7 @@ And more, added later.
>>> i.gi_running >>> i.gi_running
0 0
>>> type(i.gi_frame) >>> type(i.gi_frame)
<type 'frame'> <class 'frame'>
>>> i.gi_running = 42 >>> i.gi_running = 42
Traceback (most recent call last): Traceback (most recent call last):
... ...
...@@ -794,27 +794,27 @@ These are fine: ...@@ -794,27 +794,27 @@ These are fine:
>>> def f(): >>> def f():
... yield ... yield
>>> type(f()) >>> type(f())
<type 'generator'> <class 'generator'>
>>> def f(): >>> def f():
... if 0: ... if 0:
... yield ... yield
>>> type(f()) >>> type(f())
<type 'generator'> <class 'generator'>
>>> def f(): >>> def f():
... if 0: ... if 0:
... yield 1 ... yield 1
>>> type(f()) >>> type(f())
<type 'generator'> <class 'generator'>
>>> def f(): >>> def f():
... if "": ... if "":
... yield None ... yield None
>>> type(f()) >>> type(f())
<type 'generator'> <class 'generator'>
>>> def f(): >>> def f():
... return ... return
...@@ -838,7 +838,7 @@ These are fine: ...@@ -838,7 +838,7 @@ These are fine:
... x = 1 ... x = 1
... return ... return
>>> type(f()) >>> type(f())
<type 'generator'> <class 'generator'>
>>> def f(): >>> def f():
... if 0: ... if 0:
...@@ -846,7 +846,7 @@ These are fine: ...@@ -846,7 +846,7 @@ These are fine:
... yield 1 ... yield 1
... ...
>>> type(f()) >>> type(f())
<type 'NoneType'> <class 'NoneType'>
>>> def f(): >>> def f():
... if 0: ... if 0:
...@@ -856,7 +856,7 @@ These are fine: ...@@ -856,7 +856,7 @@ These are fine:
... def f(self): ... def f(self):
... yield 2 ... yield 2
>>> type(f()) >>> type(f())
<type 'NoneType'> <class 'NoneType'>
>>> def f(): >>> def f():
... if 0: ... if 0:
...@@ -864,7 +864,7 @@ These are fine: ...@@ -864,7 +864,7 @@ These are fine:
... if 0: ... if 0:
... yield 2 ... yield 2
>>> type(f()) >>> type(f())
<type 'generator'> <class 'generator'>
>>> def f(): >>> def f():
...@@ -1512,7 +1512,7 @@ And a more sane, but still weird usage: ...@@ -1512,7 +1512,7 @@ And a more sane, but still weird usage:
>>> def f(): list(i for i in [(yield 26)]) >>> def f(): list(i for i in [(yield 26)])
>>> type(f()) >>> type(f())
<type 'generator'> <class 'generator'>
A yield expression with augmented assignment. A yield expression with augmented assignment.
...@@ -1749,25 +1749,25 @@ enclosing function a generator: ...@@ -1749,25 +1749,25 @@ enclosing function a generator:
>>> def f(): x += yield >>> def f(): x += yield
>>> type(f()) >>> type(f())
<type 'generator'> <class 'generator'>
>>> def f(): x = yield >>> def f(): x = yield
>>> type(f()) >>> type(f())
<type 'generator'> <class 'generator'>
>>> def f(): lambda x=(yield): 1 >>> def f(): lambda x=(yield): 1
>>> type(f()) >>> type(f())
<type 'generator'> <class 'generator'>
>>> def f(): x=(i for i in (yield) if (yield)) >>> def f(): x=(i for i in (yield) if (yield))
>>> type(f()) >>> type(f())
<type 'generator'> <class 'generator'>
>>> def f(d): d[(yield "a")] = d[(yield "b")] = 27 >>> def f(d): d[(yield "a")] = d[(yield "b")] = 27
>>> data = [1,2] >>> data = [1,2]
>>> g = f(data) >>> g = f(data)
>>> type(g) >>> type(g)
<type 'generator'> <class 'generator'>
>>> g.send(None) >>> g.send(None)
'a' 'a'
>>> data >>> data
......
...@@ -27,7 +27,7 @@ Test first class ...@@ -27,7 +27,7 @@ Test first class
>>> g = (i*i for i in range(4)) >>> g = (i*i for i in range(4))
>>> type(g) >>> type(g)
<type 'generator'> <class 'generator'>
>>> list(g) >>> list(g)
[0, 1, 4, 9] [0, 1, 4, 9]
......
...@@ -78,7 +78,7 @@ Also pass another keyword. ...@@ -78,7 +78,7 @@ Also pass another keyword.
>>> class C(object, metaclass=M, other="haha"): >>> class C(object, metaclass=M, other="haha"):
... pass ... pass
... ...
Prepare called: ('C', (<type 'object'>,)) {'other': 'haha'} Prepare called: ('C', (<class 'object'>,)) {'other': 'haha'}
New called: {'other': 'haha'} New called: {'other': 'haha'}
>>> C.__class__ is M >>> C.__class__ is M
True True
...@@ -104,7 +104,7 @@ Use various combinations of explicit keywords and **kwds. ...@@ -104,7 +104,7 @@ Use various combinations of explicit keywords and **kwds.
>>> kwds = {'metaclass': M, 'other': 'haha'} >>> kwds = {'metaclass': M, 'other': 'haha'}
>>> class C(*bases, **kwds): pass >>> class C(*bases, **kwds): pass
... ...
Prepare called: ('C', (<type 'object'>,)) {'other': 'haha'} Prepare called: ('C', (<class 'object'>,)) {'other': 'haha'}
New called: {'other': 'haha'} New called: {'other': 'haha'}
>>> C.__class__ is M >>> C.__class__ is M
True True
...@@ -114,7 +114,7 @@ Use various combinations of explicit keywords and **kwds. ...@@ -114,7 +114,7 @@ Use various combinations of explicit keywords and **kwds.
>>> kwds = {'other': 'haha'} >>> kwds = {'other': 'haha'}
>>> class C(B, metaclass=M, *bases, **kwds): pass >>> 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'} New called: {'other': 'haha'}
>>> C.__class__ is M >>> C.__class__ is M
True True
......
...@@ -157,7 +157,7 @@ class IntegrationTests(TestCase): ...@@ -157,7 +157,7 @@ class IntegrationTests(TestCase):
self.assertEqual( self.assertEqual(
err.splitlines()[-2], err.splitlines()[-2],
"AssertionError: Headers (('Content-Type', 'text/plain')) must" "AssertionError: Headers (('Content-Type', 'text/plain')) must"
" be of type list: <type 'tuple'>" " be of type list: <class 'tuple'>"
) )
......
...@@ -416,12 +416,12 @@ class SimpleServerTestCase(unittest.TestCase): ...@@ -416,12 +416,12 @@ class SimpleServerTestCase(unittest.TestCase):
result = multicall() result = multicall()
# result.results contains; # result.results contains;
# [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:' # [{'faultCode': 1, 'faultString': '<class \'exceptions.Exception\'>:'
# 'method "this_is_not_exists" is not supported'>}] # 'method "this_is_not_exists" is not supported'>}]
self.assertEqual(result.results[0]['faultCode'], 1) self.assertEqual(result.results[0]['faultCode'], 1)
self.assertEqual(result.results[0]['faultString'], self.assertEqual(result.results[0]['faultString'],
'<type \'Exception\'>:method "this_is_not_exists" ' '<class \'Exception\'>:method "this_is_not_exists" '
'is not supported') 'is not supported')
except (xmlrpclib.ProtocolError, socket.error) as e: except (xmlrpclib.ProtocolError, socket.error) as e:
# ignore failures due to non-blocking socket 'unavailable' errors # ignore failures due to non-blocking socket 'unavailable' errors
......
...@@ -12,6 +12,9 @@ What's New in Python 3.0a5? ...@@ -12,6 +12,9 @@ What's New in Python 3.0a5?
Core and Builtins 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 - The command line processing was converted to pass Unicode strings
through as unmodified as possible; as a consequence, the C API through as unmodified as possible; as a consequence, the C API
related to command line arguments was changed to use wchar_t. related to command line arguments was changed to use wchar_t.
......
...@@ -600,7 +600,6 @@ static PyObject * ...@@ -600,7 +600,6 @@ static PyObject *
type_repr(PyTypeObject *type) type_repr(PyTypeObject *type)
{ {
PyObject *mod, *name, *rtn; PyObject *mod, *name, *rtn;
char *kind;
mod = type_module(type, NULL); mod = type_module(type, NULL);
if (mod == NULL) if (mod == NULL)
...@@ -613,15 +612,10 @@ type_repr(PyTypeObject *type) ...@@ -613,15 +612,10 @@ type_repr(PyTypeObject *type)
if (name == NULL) if (name == NULL)
return NULL; return NULL;
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE)
kind = "class";
else
kind = "type";
if (mod != NULL && PyUnicode_CompareWithASCIIString(mod, "builtins")) 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 else
rtn = PyUnicode_FromFormat("<%s '%s'>", kind, type->tp_name); rtn = PyUnicode_FromFormat("<class '%s'>", type->tp_name);
Py_XDECREF(mod); Py_XDECREF(mod);
Py_DECREF(name); Py_DECREF(name);
......
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