diff --git a/sphinx/directives/__init__.py b/sphinx/directives/__init__.py index 218bc6d54..181c6f81a 100644 --- a/sphinx/directives/__init__.py +++ b/sphinx/directives/__init__.py @@ -267,7 +267,7 @@ class ObjectDescription(SphinxDirective, Generic[ObjDescT]): finally: # Private attributes for ToC generation. Will be modified or removed # 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_name'] = self._toc_entry_name(signode) else: @@ -288,7 +288,7 @@ class ObjectDescription(SphinxDirective, Generic[ObjDescT]): content_node = addnodes.desc_content('', *content_children) node.append(content_node) self.transform_content(content_node) - self.env.app.emit( + self.env.events.emit( 'object-description-transform', self.domain, self.objtype, content_node ) DocFieldTransformer(self).transform_all(content_node) diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index e297ceb4b..32fd3111a 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -412,7 +412,7 @@ class Include(BaseInclude, SphinxDirective): # Emit the "include-read" event arg = [text] - self.env.app.events.emit('include-read', path, docname, arg) + self.env.events.emit('include-read', path, docname, arg) text = arg[0] # 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) # 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 self.state_machine.insert_input = _insert_input diff --git a/sphinx/domains/cpp/__init__.py b/sphinx/domains/cpp/__init__.py index 451836111..5e7942dd6 100644 --- a/sphinx/domains/cpp/__init__.py +++ b/sphinx/domains/cpp/__init__.py @@ -403,7 +403,7 @@ class CPPObject(ObjectDescription[ASTDeclaration]): if not sig_node.get('_toc_parts'): return '' - config = self.env.app.config + config = self.env.config objtype = sig_node.parent.get('objtype') if config.add_function_parentheses and objtype in {'function', 'method'}: parens = '()' diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py index ec81375a6..7ad37987b 100644 --- a/sphinx/domains/javascript.py +++ b/sphinx/domains/javascript.py @@ -230,7 +230,7 @@ class JSObject(ObjectDescription[tuple[str, str]]): if not sig_node.get('_toc_parts'): return '' - config = self.env.app.config + config = self.env.config objtype = sig_node.parent.get('objtype') if config.add_function_parentheses and objtype in {'function', 'method'}: parens = '()' diff --git a/sphinx/domains/python/_object.py b/sphinx/domains/python/_object.py index ceb7f8bf8..3e9049a1a 100644 --- a/sphinx/domains/python/_object.py +++ b/sphinx/domains/python/_object.py @@ -411,7 +411,7 @@ class PyObject(ObjectDescription[tuple[str, str]]): if not sig_node.get('_toc_parts'): return '' - config = self.env.app.config + config = self.env.config objtype = sig_node.parent.get('objtype') if config.add_function_parentheses and objtype in {'function', 'method'}: parens = '()' diff --git a/sphinx/domains/rst.py b/sphinx/domains/rst.py index 9eec281f3..f2ada04e1 100644 --- a/sphinx/domains/rst.py +++ b/sphinx/domains/rst.py @@ -75,7 +75,7 @@ class ReSTMarkup(ObjectDescription[str]): if not sig_node.get('_toc_parts'): return '' - config = self.env.app.config + config = self.env.config objtype = sig_node.parent.get('objtype') *parents, name = sig_node['_toc_parts'] if objtype == 'directive:option': diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index c5d2b0b24..60c31e254 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -584,9 +584,14 @@ class Documenter: for docstringlines in docstrings: if self.env.app: # let extensions preprocess docstrings - self.env.app.emit('autodoc-process-docstring', - self.objtype, self.fullname, self.object, - self.options, docstringlines) + self.env.events.emit( + 'autodoc-process-docstring', + self.objtype, + self.fullname, + self.object, + self.options, + docstringlines, + ) if docstringlines and docstringlines[-1]: # append a blank line to the end of the docstring @@ -793,7 +798,7 @@ class Documenter: # should be skipped if self.env.app: # 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, not keep, self.options) if skip_user is not None: @@ -1325,7 +1330,7 @@ class FunctionDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # typ kwargs.setdefault('unqualified_typehints', True) 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) args = stringify_signature(sig, **kwargs) except TypeError as exc: @@ -1564,7 +1569,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type: call = 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: sig = inspect.signature(call, bound_method=True, type_aliases=self.config.autodoc_type_aliases) @@ -1580,7 +1585,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type: new = 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: sig = inspect.signature(new, bound_method=True, type_aliases=self.config.autodoc_type_aliases) @@ -1591,7 +1596,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type: # Finally, we should have at least __init__ implemented init = get_user_defined_function_or_method(self.object, '__init__') 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: sig = inspect.signature(init, bound_method=True, type_aliases=self.config.autodoc_type_aliases) @@ -1603,7 +1608,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type: # handle it. # We don't know the exact method that inspect.signature will read # 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: sig = inspect.signature(self.object, bound_method=False, type_aliases=self.config.autodoc_type_aliases) @@ -2198,11 +2203,13 @@ class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter): # type: args = '()' else: 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, type_aliases=self.config.autodoc_type_aliases) 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, type_aliases=self.config.autodoc_type_aliases) args = stringify_signature(sig, **kwargs) @@ -2785,7 +2792,7 @@ class PropertyDocumenter(DocstringStripSignatureMixin, # type: ignore[misc] return '' # 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 return super().format_args(**kwargs)