Skip to content

Commit da25145

Browse files
authored
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.
1 parent 45a0ea9 commit da25145

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

sphinx/ext/napoleon/__init__.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -324,22 +324,17 @@ def setup(app: Sphinx) -> Dict[str, Any]:
324324

325325

326326
def _patch_python_domain() -> None:
327-
try:
328-
from sphinx.domains.python import PyTypedField
329-
except ImportError:
330-
pass
331-
else:
332-
import sphinx.domains.python
333-
from sphinx.locale import _
334-
for doc_field in sphinx.domains.python.PyObject.doc_field_types:
335-
if doc_field.name == 'parameter':
336-
doc_field.names = ('param', 'parameter', 'arg', 'argument')
337-
break
338-
sphinx.domains.python.PyObject.doc_field_types.append(
339-
PyTypedField('keyword', label=_('Keyword Arguments'),
340-
names=('keyword', 'kwarg', 'kwparam'),
341-
typerolename='obj', typenames=('paramtype', 'kwtype'),
342-
can_collapse=True))
327+
from sphinx.domains.python import PyObject, PyTypedField
328+
from sphinx.locale import _
329+
for doc_field in PyObject.doc_field_types:
330+
if doc_field.name == 'parameter':
331+
doc_field.names = ('param', 'parameter', 'arg', 'argument')
332+
break
333+
PyObject.doc_field_types.append(
334+
PyTypedField('keyword', label=_('Keyword Arguments'),
335+
names=('keyword', 'kwarg', 'kwparam'),
336+
typerolename='obj', typenames=('paramtype', 'kwtype'),
337+
can_collapse=True))
343338

344339

345340
def _process_docstring(app: Sphinx, what: str, name: str, obj: Any,

0 commit comments

Comments
 (0)