mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use attributes of `env
rather than
env.app
`
This commit is contained in:
parent
1e968be6ef
commit
c3968e9be9
@ -267,7 +267,7 @@ class ObjectDescription(SphinxDirective, Generic[ObjDescT]):
|
|||||||
finally:
|
finally:
|
||||||
# Private attributes for ToC generation. Will be modified or removed
|
# Private attributes for ToC generation. Will be modified or removed
|
||||||
# without notice.
|
# without notice.
|
||||||
if self.env.app.config.toc_object_entries:
|
if self.env.config.toc_object_entries:
|
||||||
signode['_toc_parts'] = self._object_hierarchy_parts(signode)
|
signode['_toc_parts'] = self._object_hierarchy_parts(signode)
|
||||||
signode['_toc_name'] = self._toc_entry_name(signode)
|
signode['_toc_name'] = self._toc_entry_name(signode)
|
||||||
else:
|
else:
|
||||||
@ -288,7 +288,7 @@ class ObjectDescription(SphinxDirective, Generic[ObjDescT]):
|
|||||||
content_node = addnodes.desc_content('', *content_children)
|
content_node = addnodes.desc_content('', *content_children)
|
||||||
node.append(content_node)
|
node.append(content_node)
|
||||||
self.transform_content(content_node)
|
self.transform_content(content_node)
|
||||||
self.env.app.emit(
|
self.env.events.emit(
|
||||||
'object-description-transform', self.domain, self.objtype, content_node
|
'object-description-transform', self.domain, self.objtype, content_node
|
||||||
)
|
)
|
||||||
DocFieldTransformer(self).transform_all(content_node)
|
DocFieldTransformer(self).transform_all(content_node)
|
||||||
|
@ -412,7 +412,7 @@ class Include(BaseInclude, SphinxDirective):
|
|||||||
|
|
||||||
# Emit the "include-read" event
|
# Emit the "include-read" event
|
||||||
arg = [text]
|
arg = [text]
|
||||||
self.env.app.events.emit('include-read', path, docname, arg)
|
self.env.events.emit('include-read', path, docname, arg)
|
||||||
text = arg[0]
|
text = arg[0]
|
||||||
|
|
||||||
# Split back into lines and reattach the two marker lines
|
# Split back into lines and reattach the two marker lines
|
||||||
@ -424,7 +424,7 @@ class Include(BaseInclude, SphinxDirective):
|
|||||||
return StateMachine.insert_input(self.state_machine, include_lines, source)
|
return StateMachine.insert_input(self.state_machine, include_lines, source)
|
||||||
|
|
||||||
# Only enable this patch if there are listeners for 'include-read'.
|
# Only enable this patch if there are listeners for 'include-read'.
|
||||||
if self.env.app.events.listeners.get('include-read'):
|
if self.env.events.listeners.get('include-read'):
|
||||||
# See https://github.com/python/mypy/issues/2427 for details on the mypy issue
|
# See https://github.com/python/mypy/issues/2427 for details on the mypy issue
|
||||||
self.state_machine.insert_input = _insert_input
|
self.state_machine.insert_input = _insert_input
|
||||||
|
|
||||||
|
@ -403,7 +403,7 @@ class CPPObject(ObjectDescription[ASTDeclaration]):
|
|||||||
if not sig_node.get('_toc_parts'):
|
if not sig_node.get('_toc_parts'):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
config = self.env.app.config
|
config = self.env.config
|
||||||
objtype = sig_node.parent.get('objtype')
|
objtype = sig_node.parent.get('objtype')
|
||||||
if config.add_function_parentheses and objtype in {'function', 'method'}:
|
if config.add_function_parentheses and objtype in {'function', 'method'}:
|
||||||
parens = '()'
|
parens = '()'
|
||||||
|
@ -230,7 +230,7 @@ class JSObject(ObjectDescription[tuple[str, str]]):
|
|||||||
if not sig_node.get('_toc_parts'):
|
if not sig_node.get('_toc_parts'):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
config = self.env.app.config
|
config = self.env.config
|
||||||
objtype = sig_node.parent.get('objtype')
|
objtype = sig_node.parent.get('objtype')
|
||||||
if config.add_function_parentheses and objtype in {'function', 'method'}:
|
if config.add_function_parentheses and objtype in {'function', 'method'}:
|
||||||
parens = '()'
|
parens = '()'
|
||||||
|
@ -411,7 +411,7 @@ class PyObject(ObjectDescription[tuple[str, str]]):
|
|||||||
if not sig_node.get('_toc_parts'):
|
if not sig_node.get('_toc_parts'):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
config = self.env.app.config
|
config = self.env.config
|
||||||
objtype = sig_node.parent.get('objtype')
|
objtype = sig_node.parent.get('objtype')
|
||||||
if config.add_function_parentheses and objtype in {'function', 'method'}:
|
if config.add_function_parentheses and objtype in {'function', 'method'}:
|
||||||
parens = '()'
|
parens = '()'
|
||||||
|
@ -75,7 +75,7 @@ class ReSTMarkup(ObjectDescription[str]):
|
|||||||
if not sig_node.get('_toc_parts'):
|
if not sig_node.get('_toc_parts'):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
config = self.env.app.config
|
config = self.env.config
|
||||||
objtype = sig_node.parent.get('objtype')
|
objtype = sig_node.parent.get('objtype')
|
||||||
*parents, name = sig_node['_toc_parts']
|
*parents, name = sig_node['_toc_parts']
|
||||||
if objtype == 'directive:option':
|
if objtype == 'directive:option':
|
||||||
|
@ -584,9 +584,14 @@ class Documenter:
|
|||||||
for docstringlines in docstrings:
|
for docstringlines in docstrings:
|
||||||
if self.env.app:
|
if self.env.app:
|
||||||
# let extensions preprocess docstrings
|
# let extensions preprocess docstrings
|
||||||
self.env.app.emit('autodoc-process-docstring',
|
self.env.events.emit(
|
||||||
self.objtype, self.fullname, self.object,
|
'autodoc-process-docstring',
|
||||||
self.options, docstringlines)
|
self.objtype,
|
||||||
|
self.fullname,
|
||||||
|
self.object,
|
||||||
|
self.options,
|
||||||
|
docstringlines,
|
||||||
|
)
|
||||||
|
|
||||||
if docstringlines and docstringlines[-1]:
|
if docstringlines and docstringlines[-1]:
|
||||||
# append a blank line to the end of the docstring
|
# append a blank line to the end of the docstring
|
||||||
@ -793,7 +798,7 @@ class Documenter:
|
|||||||
# should be skipped
|
# should be skipped
|
||||||
if self.env.app:
|
if self.env.app:
|
||||||
# let extensions preprocess docstrings
|
# let extensions preprocess docstrings
|
||||||
skip_user = self.env.app.emit_firstresult(
|
skip_user = self.env.events.emit_firstresult(
|
||||||
'autodoc-skip-member', self.objtype, membername, member,
|
'autodoc-skip-member', self.objtype, membername, member,
|
||||||
not keep, self.options)
|
not keep, self.options)
|
||||||
if skip_user is not None:
|
if skip_user is not None:
|
||||||
@ -1325,7 +1330,7 @@ class FunctionDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # typ
|
|||||||
kwargs.setdefault('unqualified_typehints', True)
|
kwargs.setdefault('unqualified_typehints', True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.env.app.emit('autodoc-before-process-signature', self.object, False)
|
self.env.events.emit('autodoc-before-process-signature', self.object, False)
|
||||||
sig = inspect.signature(self.object, type_aliases=self.config.autodoc_type_aliases)
|
sig = inspect.signature(self.object, type_aliases=self.config.autodoc_type_aliases)
|
||||||
args = stringify_signature(sig, **kwargs)
|
args = stringify_signature(sig, **kwargs)
|
||||||
except TypeError as exc:
|
except TypeError as exc:
|
||||||
@ -1564,7 +1569,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
|
|||||||
call = None
|
call = None
|
||||||
|
|
||||||
if call is not None:
|
if call is not None:
|
||||||
self.env.app.emit('autodoc-before-process-signature', call, True)
|
self.env.events.emit('autodoc-before-process-signature', call, True)
|
||||||
try:
|
try:
|
||||||
sig = inspect.signature(call, bound_method=True,
|
sig = inspect.signature(call, bound_method=True,
|
||||||
type_aliases=self.config.autodoc_type_aliases)
|
type_aliases=self.config.autodoc_type_aliases)
|
||||||
@ -1580,7 +1585,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
|
|||||||
new = None
|
new = None
|
||||||
|
|
||||||
if new is not None:
|
if new is not None:
|
||||||
self.env.app.emit('autodoc-before-process-signature', new, True)
|
self.env.events.emit('autodoc-before-process-signature', new, True)
|
||||||
try:
|
try:
|
||||||
sig = inspect.signature(new, bound_method=True,
|
sig = inspect.signature(new, bound_method=True,
|
||||||
type_aliases=self.config.autodoc_type_aliases)
|
type_aliases=self.config.autodoc_type_aliases)
|
||||||
@ -1591,7 +1596,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
|
|||||||
# Finally, we should have at least __init__ implemented
|
# Finally, we should have at least __init__ implemented
|
||||||
init = get_user_defined_function_or_method(self.object, '__init__')
|
init = get_user_defined_function_or_method(self.object, '__init__')
|
||||||
if init is not None:
|
if init is not None:
|
||||||
self.env.app.emit('autodoc-before-process-signature', init, True)
|
self.env.events.emit('autodoc-before-process-signature', init, True)
|
||||||
try:
|
try:
|
||||||
sig = inspect.signature(init, bound_method=True,
|
sig = inspect.signature(init, bound_method=True,
|
||||||
type_aliases=self.config.autodoc_type_aliases)
|
type_aliases=self.config.autodoc_type_aliases)
|
||||||
@ -1603,7 +1608,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
|
|||||||
# handle it.
|
# handle it.
|
||||||
# We don't know the exact method that inspect.signature will read
|
# We don't know the exact method that inspect.signature will read
|
||||||
# the signature from, so just pass the object itself to our hook.
|
# the signature from, so just pass the object itself to our hook.
|
||||||
self.env.app.emit('autodoc-before-process-signature', self.object, False)
|
self.env.events.emit('autodoc-before-process-signature', self.object, False)
|
||||||
try:
|
try:
|
||||||
sig = inspect.signature(self.object, bound_method=False,
|
sig = inspect.signature(self.object, bound_method=False,
|
||||||
type_aliases=self.config.autodoc_type_aliases)
|
type_aliases=self.config.autodoc_type_aliases)
|
||||||
@ -2198,11 +2203,13 @@ class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter): # type:
|
|||||||
args = '()'
|
args = '()'
|
||||||
else:
|
else:
|
||||||
if inspect.isstaticmethod(self.object, cls=self.parent, name=self.object_name):
|
if inspect.isstaticmethod(self.object, cls=self.parent, name=self.object_name):
|
||||||
self.env.app.emit('autodoc-before-process-signature', self.object, False)
|
self.env.events.emit(
|
||||||
|
'autodoc-before-process-signature', self.object, False
|
||||||
|
)
|
||||||
sig = inspect.signature(self.object, bound_method=False,
|
sig = inspect.signature(self.object, bound_method=False,
|
||||||
type_aliases=self.config.autodoc_type_aliases)
|
type_aliases=self.config.autodoc_type_aliases)
|
||||||
else:
|
else:
|
||||||
self.env.app.emit('autodoc-before-process-signature', self.object, True)
|
self.env.events.emit('autodoc-before-process-signature', self.object, True)
|
||||||
sig = inspect.signature(self.object, bound_method=True,
|
sig = inspect.signature(self.object, bound_method=True,
|
||||||
type_aliases=self.config.autodoc_type_aliases)
|
type_aliases=self.config.autodoc_type_aliases)
|
||||||
args = stringify_signature(sig, **kwargs)
|
args = stringify_signature(sig, **kwargs)
|
||||||
@ -2785,7 +2792,7 @@ class PropertyDocumenter(DocstringStripSignatureMixin, # type: ignore[misc]
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
# update the annotations of the property getter
|
# update the annotations of the property getter
|
||||||
self.env.app.emit('autodoc-before-process-signature', func, False)
|
self.env.events.emit('autodoc-before-process-signature', func, False)
|
||||||
# correctly format the arguments for a property
|
# correctly format the arguments for a property
|
||||||
return super().format_args(**kwargs)
|
return super().format_args(**kwargs)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user