mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #9281 from tk0miya/9272_enum_for_defargs
Close #9272: autodoc: Render enum values for the default argument value better
This commit is contained in:
commit
7dbe8ebf1b
1
CHANGES
1
CHANGES
@ -35,6 +35,7 @@ Features added
|
||||
* #8061, #9218: autodoc: Support variable comment for alias classes
|
||||
* #3014: autodoc: Add :event:`autodoc-process-bases` to modify the base classes
|
||||
of the class definitions
|
||||
* #9272: autodoc: Render enum values for the default argument value better
|
||||
* #3257: autosummary: Support instance attributes for classes
|
||||
* #9129: html search: Show search summaries when html_copy_source = False
|
||||
* #9120: html theme: Eliminate prompt characters of code-block from copyable
|
||||
|
@ -442,14 +442,14 @@ def object_description(object: Any) -> str:
|
||||
(object_description(key), object_description(object[key]))
|
||||
for key in sorted_keys)
|
||||
return "{%s}" % ", ".join(items)
|
||||
if isinstance(object, set):
|
||||
elif isinstance(object, set):
|
||||
try:
|
||||
sorted_values = sorted(object)
|
||||
except TypeError:
|
||||
pass # Cannot sort set values, fall back to generic repr
|
||||
else:
|
||||
return "{%s}" % ", ".join(object_description(x) for x in sorted_values)
|
||||
if isinstance(object, frozenset):
|
||||
elif isinstance(object, frozenset):
|
||||
try:
|
||||
sorted_values = sorted(object)
|
||||
except TypeError:
|
||||
@ -457,6 +457,9 @@ def object_description(object: Any) -> str:
|
||||
else:
|
||||
return "frozenset({%s})" % ", ".join(object_description(x)
|
||||
for x in sorted_values)
|
||||
elif isinstance(object, enum.Enum):
|
||||
return "%s.%s" % (object.__class__.__name__, object.name)
|
||||
|
||||
try:
|
||||
s = repr(object)
|
||||
except Exception as exc:
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
import ast
|
||||
import datetime
|
||||
import enum
|
||||
import functools
|
||||
import sys
|
||||
import types
|
||||
@ -516,6 +517,14 @@ def test_dict_customtype():
|
||||
assert "<CustomType(2)>: 2" in description
|
||||
|
||||
|
||||
def test_object_description_enum():
|
||||
class MyEnum(enum.Enum):
|
||||
FOO = 1
|
||||
BAR = 2
|
||||
|
||||
assert inspect.object_description(MyEnum.FOO) == "MyEnum.FOO"
|
||||
|
||||
|
||||
def test_getslots():
|
||||
class Foo:
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user