diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index 8fefc0737e0..24fbe33d4e3 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -612,16 +612,6 @@ def get_doctree(self, docname: str) -> nodes.document: def master_doctree(self) -> nodes.document: return self.get_doctree(self.config.root_doc) - def get_doctree_write(self, docname: str) -> nodes.document: - """Read the doctree from pickle for the write phase.""" - try: - doctree = self._write_doc_doctree_cache.pop(docname) - doctree.settings.env = self - doctree.reporter = LoggingReporter(self.doc2path(docname)) - except KeyError: - doctree = self.get_doctree(docname) - return doctree - def get_and_resolve_doctree( self, docname: str, @@ -630,9 +620,16 @@ def get_and_resolve_doctree( prune_toctrees: bool = True, includehidden: bool = False, ) -> nodes.document: - """Get the doctree, resolve cross-references and toctrees and return it.""" + """Read the doctree from the pickle, resolve cross-references and + toctrees and return it. + """ if doctree is None: - doctree = self.get_doctree_write(docname) + try: + doctree = self._write_doc_doctree_cache.pop(docname) + doctree.settings.env = self + doctree.reporter = LoggingReporter(self.doc2path(docname)) + except KeyError: + doctree = self.get_doctree(docname) # resolve all pending cross-references self.apply_post_transforms(doctree, docname)