Ignore extra argument type annotations

Closes #186
This commit is contained in:
Ashley Whetter 2020-01-07 16:23:12 -08:00
parent d40122948b
commit 9c91de9370
3 changed files with 23 additions and 0 deletions

View File

@ -11,6 +11,14 @@ Features
* `#151 <https://github.com/readthedocs/sphinx-autoapi/issues/151>`: (Python) Added the ``autoapi_python_use_implicit_namespaces`` option to allow * `#151 <https://github.com/readthedocs/sphinx-autoapi/issues/151>`: (Python) Added the ``autoapi_python_use_implicit_namespaces`` option to allow
AutoAPI to search for implicit namespace packages. AutoAPI to search for implicit namespace packages.
Bug Fixes
^^^^^^^^^
* `#186 <https://github.com/readthedocs/sphinx-autoapi/issues/186>`: (Python)
Fixed an exception when there are too many argument type annotations
in a type comment.
Instead, a warning is raised to indicate that the extra annotations
will be ignored.
v1.2.1 (2019-10-9) v1.2.1 (2019-10-9)
------------------ ------------------

View File

@ -8,6 +8,9 @@ import sys
import astroid import astroid
import astroid.nodes import astroid.nodes
import sphinx.util.logging
_LOGGER = sphinx.util.logging.getLogger(__name__)
if sys.version_info < (3,): if sys.version_info < (3,):
@ -432,6 +435,13 @@ def format_args(args_node):
result.append("/") result.append("/")
if args_node.args: if args_node.args:
if len(args_node.args) < len(annotations):
msg = "Ignoring extra argument type annotation(s) on {}".format(
args_node.scope().qname()
)
_LOGGER.warning(msg)
annotations = annotations[: len(args_node.args)]
result.append( result.append(
_format_args(args_node.args, positional_or_keyword_defaults, annotations) _format_args(args_node.args, positional_or_keyword_defaults, annotations)
) )

View File

@ -39,3 +39,8 @@ class A:
global_a = A() # type: A global_a = A() # type: A
def f3(first_arg, **kwargs):
# type: (first_arg, Any) -> None
"""Annotation incorrectly leaves out `**`."""