Fix #7161: autodoc: typehints extension does not support parallel build

This commit is contained in:
Takeshi KOMIYA 2020-02-16 20:27:51 +09:00
parent 1339948dce
commit 68e248fa73
2 changed files with 13 additions and 6 deletions

View File

@ -19,6 +19,7 @@ Bugs fixed
* #7138: autodoc: ``autodoc.typehints`` crashed when variable has unbound object * #7138: autodoc: ``autodoc.typehints`` crashed when variable has unbound object
as a value as a value
* #7156: autodoc: separator for keyword only arguments is not shown * #7156: autodoc: separator for keyword only arguments is not shown
* #7161: autodoc: typehints extension does not support parallel build
Testing Testing
-------- --------

View File

@ -18,19 +18,19 @@ from docutils.nodes import Element
from sphinx import addnodes from sphinx import addnodes
from sphinx.application import Sphinx from sphinx.application import Sphinx
from sphinx.config import ENUM from sphinx.config import Config, ENUM
from sphinx.util import inspect, typing from sphinx.util import inspect, typing
def config_inited(app, config): def config_inited(app: Sphinx, config: Config) -> None:
if config.autodoc_typehints == 'description': if config.autodoc_typehints == 'description':
# HACK: override this to make autodoc suppressing typehints in signatures # HACK: override this to make autodoc suppressing typehints in signatures
config.autodoc_typehints = 'none' config.autodoc_typehints = 'none' # type: ignore
# preserve user settings # preserve user settings
app._autodoc_typehints_description = True app._autodoc_typehints_description = True # type: ignore
else: else:
app._autodoc_typehints_description = False app._autodoc_typehints_description = False # type: ignore
def record_typehints(app: Sphinx, objtype: str, name: str, obj: Any, def record_typehints(app: Sphinx, objtype: str, name: str, obj: Any,
@ -140,10 +140,16 @@ def modify_field_list(node: nodes.field_list, annotations: Dict[str, str]) -> No
node += field node += field
def setup(app): def setup(app: Sphinx) -> Dict[str, Any]:
app.setup_extension('sphinx.ext.autodoc') app.setup_extension('sphinx.ext.autodoc')
app.config.values['autodoc_typehints'] = ('signature', True, app.config.values['autodoc_typehints'] = ('signature', True,
ENUM("signature", "description", "none")) ENUM("signature", "description", "none"))
app.connect('config-inited', config_inited) app.connect('config-inited', config_inited)
app.connect('autodoc-process-signature', record_typehints) app.connect('autodoc-process-signature', record_typehints)
app.connect('object-description-transform', merge_typehints) app.connect('object-description-transform', merge_typehints)
return {
'version': 'builtin',
'parallel_read_safe': True,
'parallel_write_safe': True,
}