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
|
* #8061, #9218: autodoc: Support variable comment for alias classes
|
||||||
* #3014: autodoc: Add :event:`autodoc-process-bases` to modify the base classes
|
* #3014: autodoc: Add :event:`autodoc-process-bases` to modify the base classes
|
||||||
of the class definitions
|
of the class definitions
|
||||||
|
* #9272: autodoc: Render enum values for the default argument value better
|
||||||
* #3257: autosummary: Support instance attributes for classes
|
* #3257: autosummary: Support instance attributes for classes
|
||||||
* #9129: html search: Show search summaries when html_copy_source = False
|
* #9129: html search: Show search summaries when html_copy_source = False
|
||||||
* #9120: html theme: Eliminate prompt characters of code-block from copyable
|
* #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]))
|
(object_description(key), object_description(object[key]))
|
||||||
for key in sorted_keys)
|
for key in sorted_keys)
|
||||||
return "{%s}" % ", ".join(items)
|
return "{%s}" % ", ".join(items)
|
||||||
if isinstance(object, set):
|
elif isinstance(object, set):
|
||||||
try:
|
try:
|
||||||
sorted_values = sorted(object)
|
sorted_values = sorted(object)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass # Cannot sort set values, fall back to generic repr
|
pass # Cannot sort set values, fall back to generic repr
|
||||||
else:
|
else:
|
||||||
return "{%s}" % ", ".join(object_description(x) for x in sorted_values)
|
return "{%s}" % ", ".join(object_description(x) for x in sorted_values)
|
||||||
if isinstance(object, frozenset):
|
elif isinstance(object, frozenset):
|
||||||
try:
|
try:
|
||||||
sorted_values = sorted(object)
|
sorted_values = sorted(object)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
@ -457,6 +457,9 @@ def object_description(object: Any) -> str:
|
|||||||
else:
|
else:
|
||||||
return "frozenset({%s})" % ", ".join(object_description(x)
|
return "frozenset({%s})" % ", ".join(object_description(x)
|
||||||
for x in sorted_values)
|
for x in sorted_values)
|
||||||
|
elif isinstance(object, enum.Enum):
|
||||||
|
return "%s.%s" % (object.__class__.__name__, object.name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s = repr(object)
|
s = repr(object)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
import ast
|
import ast
|
||||||
import datetime
|
import datetime
|
||||||
|
import enum
|
||||||
import functools
|
import functools
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
@ -516,6 +517,14 @@ def test_dict_customtype():
|
|||||||
assert "<CustomType(2)>: 2" in description
|
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():
|
def test_getslots():
|
||||||
class Foo:
|
class Foo:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user