From 7fa399843817246e82454eade6ef58aac8d8d421 Mon Sep 17 00:00:00 2001 From: Ashley Whetter Date: Tue, 30 May 2023 19:03:32 -0700 Subject: [PATCH] Fix separated type comments for arguments not merging correctly in Python 3.7 --- autoapi/mappers/python/astroid_utils.py | 4 ---- docs/changes/+d02885a9.bugfix.rst | 1 + tests/python/test_pyintegration.py | 8 ++------ tests/test_astroid_utils.py | 19 +++++++++++++++++++ 4 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 docs/changes/+d02885a9.bugfix.rst diff --git a/autoapi/mappers/python/astroid_utils.py b/autoapi/mappers/python/astroid_utils.py index 873e9413..42fb5de9 100644 --- a/autoapi/mappers/python/astroid_utils.py +++ b/autoapi/mappers/python/astroid_utils.py @@ -1,7 +1,6 @@ import builtins import itertools import re -import sys import astroid import astroid.nodes @@ -393,9 +392,6 @@ def get_module_all(node): def _is_ellipsis(node): - if sys.version_info < (3, 8): - return isinstance(node, astroid.Ellipsis) - return isinstance(node, astroid.Const) and node.value == Ellipsis diff --git a/docs/changes/+d02885a9.bugfix.rst b/docs/changes/+d02885a9.bugfix.rst new file mode 100644 index 00000000..52690879 --- /dev/null +++ b/docs/changes/+d02885a9.bugfix.rst @@ -0,0 +1 @@ +Fix separated type comments for arguments not merging correctly in Python 3.7 diff --git a/tests/python/test_pyintegration.py b/tests/python/test_pyintegration.py index 36b84917..483dadcc 100644 --- a/tests/python/test_pyintegration.py +++ b/tests/python/test_pyintegration.py @@ -355,9 +355,7 @@ def test_annotations(self, parse): f = example_file.find(id="example.f") assert f - # TODO: Fix for all versions - if sys.version_info >= (3, 8): - assert f.find(class_="sig-param").text == "start: int" + assert f.find(class_="sig-param").text == "start: int" assert f.find(class_="sig-return-typehint").text == "Iterable[int]" mixed_list = example_file.find(id="example.mixed_list") @@ -507,9 +505,7 @@ def test_integration(self, parse): f = example_file.find(id="example.f") assert f - # TODO: Fix for all versions - if sys.version_info >= (3, 8): - assert f.find(class_="sig-param").text == "start: int" + assert f.find(class_="sig-param").text == "start: int" assert f.find(class_="sig-return-typehint").text == "Iterable[int]" mixed_list = example_file.find(id="example.mixed_list") diff --git a/tests/test_astroid_utils.py b/tests/test_astroid_utils.py index 2402f5eb..1e0d7251 100644 --- a/tests/test_astroid_utils.py +++ b/tests/test_astroid_utils.py @@ -163,6 +163,25 @@ def func({}) -> str: #@ annotations = astroid_utils.get_args_info(node.args) assert annotations == expected + def test_parse_split_type_comments(self): + node = astroid.extract_node( + """ + def func( + a, # type: int + b, # type: int + ): # type: (...) -> str + pass + """ + ) + + annotations = astroid_utils.get_args_info(node.args) + + expected = [ + (None, "a", "int", None), + (None, "b", "int", None), + ] + assert annotations == expected + @pytest.mark.parametrize( "signature,expected", [