diff --git a/CHANGELOG.rst b/CHANGELOG.rst index df11f72..9640f2a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,14 @@ Features * `#151 `: (Python) Added the ``autoapi_python_use_implicit_namespaces`` option to allow AutoAPI to search for implicit namespace packages. +Bug Fixes +^^^^^^^^^ +* `#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) ------------------ diff --git a/autoapi/mappers/python/astroid_utils.py b/autoapi/mappers/python/astroid_utils.py index 5645344..c8083c3 100644 --- a/autoapi/mappers/python/astroid_utils.py +++ b/autoapi/mappers/python/astroid_utils.py @@ -8,6 +8,9 @@ import sys import astroid import astroid.nodes +import sphinx.util.logging + +_LOGGER = sphinx.util.logging.getLogger(__name__) if sys.version_info < (3,): @@ -432,6 +435,13 @@ def format_args(args_node): result.append("/") 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( _format_args(args_node.args, positional_or_keyword_defaults, annotations) ) diff --git a/tests/python/pyannotationcommentsexample/example/example.py b/tests/python/pyannotationcommentsexample/example/example.py index 648684c..9ac18fc 100644 --- a/tests/python/pyannotationcommentsexample/example/example.py +++ b/tests/python/pyannotationcommentsexample/example/example.py @@ -39,3 +39,8 @@ class A: global_a = A() # type: A + + +def f3(first_arg, **kwargs): + # type: (first_arg, Any) -> None + """Annotation incorrectly leaves out `**`."""