The Wayback Machine - https://web.archive.org/web/20250613211228/https://github.com/python/cpython/issues/111250
Skip to content

Do we still need test.support.sortdict? #111250

Open
@sobolevn

Description

@sobolevn

It is documented as:

.. function:: sortdict(dict)

   Return a repr of *dict* with keys sorted.

Here's what it does:

def sortdict(dict):
"Like repr(dict), but in sorted order."
items = sorted(dict.items())
reprpairs = ["%r: %r" % pair for pair in items]
withcommas = ", ".join(reprpairs)
return "{%s}" % withcommas

But, since python3.7 (?) dicts are sorted.

Here's the list of its usages:

» ag sortdict
Misc/HISTORY
24694:  sortdict(dict) function for a simple way to display a dict in sorted

Lib/test/test_support.py
311:    def test_sortdict(self):
312:        self.assertEqual(support.sortdict({3:3, 2:2, 1:1}), "{1: 1, 2: 2, 3: 3}")

Lib/test/test_descrtut.py
11:from test.support import sortdict
62:    >>> print(sortdict(a))              # show the result
99:    >>> print(sortdict(a.__dict__))

Lib/test/test_pyexpat.py
16:from test.support import sortdict
93:                            sortdict(attrs))

Lib/test/support/__init__.py
61:    "swap_attr", "Matcher", "set_memlimit", "SuppressCrashReport", "sortdict",
624:def sortdict(dict):

Lib/test/test_extcall.py
16:    ...     print(a, support.sortdict(k))
19:    ...     print(x, y, support.sortdict(z))

Doc/library/test.rst
486:.. function:: sortdict(dict)

So, the question is: do we still need it? For backward compat or something.
If not, I can send a PR with its removal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions