mirror of https://github.com/python/cpython
Fixed repr of dictionary views.
This commit is contained in:
parent
ae7731af45
commit
58a96efde5
|
@ -72,9 +72,18 @@ class DictSetTest(unittest.TestCase):
|
|||
def test_dict_repr(self):
|
||||
d = {1: 10, "a": "ABC"}
|
||||
self.assertTrue(isinstance(repr(d), str))
|
||||
self.assertTrue(isinstance(repr(d.viewitems()), str))
|
||||
self.assertTrue(isinstance(repr(d.viewkeys()), str))
|
||||
self.assertTrue(isinstance(repr(d.viewvalues()), str))
|
||||
r = repr(d.viewitems())
|
||||
self.assertTrue(isinstance(r, str))
|
||||
self.assertTrue(r == "dict_items([('a', 'ABC'), (1, 10)])" or
|
||||
r == "dict_items([(1, 10), ('a', 'ABC')])")
|
||||
r = repr(d.viewkeys())
|
||||
self.assertTrue(isinstance(r, str))
|
||||
self.assertTrue(r == "dict_keys(['a', 1])" or
|
||||
r == "dict_keys([1, 'a'])")
|
||||
r = repr(d.viewvalues())
|
||||
self.assertTrue(isinstance(r, str))
|
||||
self.assertTrue(r == "dict_values(['ABC', 10])" or
|
||||
r == "dict_values([10, 'ABC'])")
|
||||
|
||||
|
||||
def test_main():
|
||||
|
|
|
@ -2886,7 +2886,8 @@ dictview_repr(dictviewobject *dv)
|
|||
return NULL;
|
||||
|
||||
seq_str = PyObject_Repr(seq);
|
||||
result = PyString_FromFormat("%s(%s)", Py_TYPE(dv)->tp_name, seq_str);
|
||||
result = PyString_FromFormat("%s(%s)", Py_TYPE(dv)->tp_name,
|
||||
PyString_AS_STRING(seq_str));
|
||||
Py_DECREF(seq_str);
|
||||
Py_DECREF(seq);
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue