Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/test/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,9 @@ def test_update(self):
self.assertEqual(copy, frozendict({'x': 1}))

def test_repr(self):
d = frozendict()
self.assertEqual(repr(d), "frozendict()")

d = frozendict(x=1, y=2)
self.assertEqual(repr(d), "frozendict({'x': 1, 'y': 2})")

Expand Down
5 changes: 5 additions & 0 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -7868,6 +7868,11 @@ static PyMethodDef frozendict_methods[] = {
static PyObject *
frozendict_repr(PyObject *self)
{
PyDictObject *mp = (PyDictObject *)self;
if (mp->ma_used == 0) {
return PyUnicode_FromFormat("%s()", Py_TYPE(self)->tp_name);
}

PyObject *repr = anydict_repr_impl(self);
if (repr == NULL) {
return NULL;
Expand Down
Loading