mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
inspect: Sort dictionary keys when possible
This should help for reproducible builds and for finding items in large dictionaries.
This commit is contained in:
parent
92cdbb99f2
commit
49e486ff47
@ -203,6 +203,14 @@ def safe_getmembers(object, predicate=None, attr_getter=safe_getattr):
|
||||
def object_description(object):
|
||||
# type: (Any) -> unicode
|
||||
"""A repr() implementation that returns text safe to use in reST context."""
|
||||
if isinstance(object, dict):
|
||||
try:
|
||||
sorted_keys = sorted(object)
|
||||
except TypeError:
|
||||
pass # Cannot sort dict keys, fall back to generic repr
|
||||
else:
|
||||
items = ("%r: %r" % (key, object[key]) for key in sorted_keys)
|
||||
return "{%s}" % ", ".join(items)
|
||||
try:
|
||||
s = repr(object)
|
||||
except Exception:
|
||||
|
Loading…
Reference in New Issue
Block a user