Fix #7850: autodoc: KeyError is raised for invalid mark up

This commit is contained in:
Takeshi KOMIYA 2020-06-21 17:53:04 +09:00
parent da395b4132
commit 4e739b85ee
3 changed files with 20 additions and 5 deletions

View File

@ -19,6 +19,8 @@ Bugs fixed
* #7844: autodoc: Failed to detect module when relative module name given * #7844: autodoc: Failed to detect module when relative module name given
* #7856: autodoc: AttributeError is raised when non-class object is given to * #7856: autodoc: AttributeError is raised when non-class object is given to
the autoclass directive the autoclass directive
* #7850: autodoc: KeyError is raised for invalid mark up when autodoc_typehints
is 'description'
Testing Testing
-------- --------

View File

@ -46,11 +46,16 @@ def merge_typehints(app: Sphinx, domain: str, objtype: str, contentnode: Element
if objtype == 'class' and app.config.autoclass_content not in ('init', 'both'): if objtype == 'class' and app.config.autoclass_content not in ('init', 'both'):
return return
try:
signature = cast(addnodes.desc_signature, contentnode.parent[0]) signature = cast(addnodes.desc_signature, contentnode.parent[0])
if signature['module']: if signature['module']:
fullname = '.'.join([signature['module'], signature['fullname']]) fullname = '.'.join([signature['module'], signature['fullname']])
else: else:
fullname = signature['fullname'] fullname = signature['fullname']
except KeyError:
# signature node does not have valid context info for the target object
return
annotations = app.env.temp_data.get('annotations', {}) annotations = app.env.temp_data.get('annotations', {})
if annotations.get(fullname, {}): if annotations.get(fullname, {}):
field_lists = [n for n in contentnode if isinstance(n, nodes.field_list)] field_lists = [n for n in contentnode if isinstance(n, nodes.field_list)]

View File

@ -13,6 +13,8 @@ import sys
import pytest import pytest
from sphinx.testing import restructuredtext
from test_ext_autodoc import do_autodoc from test_ext_autodoc import do_autodoc
IS_PYPY = platform.python_implementation() == 'PyPy' IS_PYPY = platform.python_implementation() == 'PyPy'
@ -633,6 +635,12 @@ def test_autodoc_typehints_description(app):
in context) in context)
@pytest.mark.sphinx('text', testroot='ext-autodoc',
confoverrides={'autodoc_typehints': "description"})
def test_autodoc_typehints_description_for_invalid_node(app):
text = ".. py:function:: hello; world"
restructuredtext.parse(app, text) # raises no error
@pytest.mark.sphinx('html', testroot='ext-autodoc') @pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_default_options(app): def test_autodoc_default_options(app):