Skip to content
Permalink
Browse files Browse the repository at this point in the history
WIP
  • Loading branch information
lamby committed Feb 15, 2023
1 parent 8de6638 commit 4ad7670
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sphinx/util/inspect.py
Expand Up @@ -386,6 +386,13 @@ def object_description(object: Any) -> str:
for x in sorted_values)
elif isinstance(object, enum.Enum):
return f"{object.__class__.__name__}.{object.name}"
elif isinstance(object, tuple):
return "(%s%s)" % (
", ".join(object_description(x) for x in object),
"," if len(object) == 1 else ""
)
elif isinstance(object, list):
return "[%s]" % ", ".join(object_description(x) for x in object)

try:
s = repr(object)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_util_inspect.py
Expand Up @@ -533,6 +533,16 @@ def test_frozenset_sorting_fallback():
assert description in ("frozenset({1, None})", "frozenset({None, 1})")


def test_nested_tuple_sorting():
tuple_ = ({"c", "b", "a"},) # nb. trailing comma
description = inspect.object_description(tuple_)
assert description == "({'a', 'b', 'c'},)"

tuple_ = ({"c", "b", "a"}, {"f", "e", "d"})
description = inspect.object_description(tuple_)
assert description == "({'a', 'b', 'c'}, {'d', 'e', 'f'})"


def test_dict_customtype():
class CustomType:
def __init__(self, value):
Expand Down

0 comments on commit 4ad7670

Please sign in to comment.