From da25145d0804240de0351d33697539306f3d10a7 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 29 Dec 2022 15:11:11 +0100 Subject: [PATCH] Remove unnecessary conditional import in ``sphinx.ext.napoleon`` (#11043) The conditional import could have been useful for the external sphinxcontrib.napoleon (to keep backcompat with older versions of sphinx), but seems just confusing for a builtin extension. --- sphinx/ext/napoleon/__init__.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/sphinx/ext/napoleon/__init__.py b/sphinx/ext/napoleon/__init__.py index 06ca8277901..e1097053b52 100644 --- a/sphinx/ext/napoleon/__init__.py +++ b/sphinx/ext/napoleon/__init__.py @@ -324,22 +324,17 @@ def setup(app: Sphinx) -> Dict[str, Any]: def _patch_python_domain() -> None: - try: - from sphinx.domains.python import PyTypedField - except ImportError: - pass - else: - import sphinx.domains.python - from sphinx.locale import _ - for doc_field in sphinx.domains.python.PyObject.doc_field_types: - if doc_field.name == 'parameter': - doc_field.names = ('param', 'parameter', 'arg', 'argument') - break - sphinx.domains.python.PyObject.doc_field_types.append( - PyTypedField('keyword', label=_('Keyword Arguments'), - names=('keyword', 'kwarg', 'kwparam'), - typerolename='obj', typenames=('paramtype', 'kwtype'), - can_collapse=True)) + from sphinx.domains.python import PyObject, PyTypedField + from sphinx.locale import _ + for doc_field in PyObject.doc_field_types: + if doc_field.name == 'parameter': + doc_field.names = ('param', 'parameter', 'arg', 'argument') + break + PyObject.doc_field_types.append( + PyTypedField('keyword', label=_('Keyword Arguments'), + names=('keyword', 'kwarg', 'kwparam'), + typerolename='obj', typenames=('paramtype', 'kwtype'), + can_collapse=True)) def _process_docstring(app: Sphinx, what: str, name: str, obj: Any,