mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-10-25 22:50:22 -05:00
Extract the `_docstring_source_name()` function (#13972)
This commit is contained in:
1 parent
1156555fcc
commit
b5870e6904
2 files changed
+39
-29
No files matched your search
@@ -4,6 +4,7 @@ from enum import IntEnum
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sphinx.ext.autodoc import ClassDocumenter, bool_option
|
||||
from sphinx.ext.autodoc._documenters import _docstring_source_name
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
@@ -31,27 +32,33 @@ class IntEnumDocumenter(ClassDocumenter):
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
def add_line(self, line: str, source: str = '', *lineno: int, indent: str) -> None:
|
||||
"""Append one line of generated reST to the output."""
|
||||
analyzer_source = '' if self.analyzer is None else self.analyzer.srcname
|
||||
source_name = _docstring_source_name(props=self.props, source=analyzer_source)
|
||||
if line.strip(): # not a blank line
|
||||
self.directive.result.append(indent + line, source_name, *lineno)
|
||||
else:
|
||||
self.directive.result.append('', source_name, *lineno)
|
||||
|
||||
def add_directive_header(self, *, indent: str) -> None:
|
||||
super().add_directive_header(indent=indent)
|
||||
self.add_line(' :final:', self.get_sourcename(), indent=indent)
|
||||
self.add_line(' :final:', indent=indent)
|
||||
|
||||
def add_content(self, more_content: StringList | None, *, indent: str) -> None:
|
||||
super().add_content(more_content, indent=indent)
|
||||
|
||||
source_name = self.get_sourcename()
|
||||
enum_object: IntEnum = self.props._obj
|
||||
use_hex = self.options.hex
|
||||
self.add_line('', source_name, indent=indent)
|
||||
self.add_line('', indent=indent)
|
||||
|
||||
for the_member_name, enum_member in enum_object.__members__.items(): # type: ignore[attr-defined]
|
||||
the_member_value = enum_member.value
|
||||
if use_hex:
|
||||
the_member_value = hex(the_member_value)
|
||||
|
||||
self.add_line(
|
||||
f'**{the_member_name}**: {the_member_value}', source_name, indent=indent
|
||||
)
|
||||
self.add_line('', source_name, indent=indent)
|
||||
self.add_line(f'**{the_member_name}**: {the_member_value}', indent=indent)
|
||||
self.add_line('', indent=indent)
|
||||
|
||||
|
||||
def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
|
||||
Reference in new issue
Block a user