Skip to content

Commit

Permalink
Fix separated type comments for arguments not merging correctly in Py…
Browse files Browse the repository at this point in the history
…thon 3.7
  • Loading branch information
AWhetter committed May 31, 2023
1 parent 434ef83 commit 7fa3998
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
4 changes: 0 additions & 4 deletions autoapi/mappers/python/astroid_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import builtins
import itertools
import re
import sys

import astroid
import astroid.nodes
Expand Down Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions docs/changes/+d02885a9.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix separated type comments for arguments not merging correctly in Python 3.7
8 changes: 2 additions & 6 deletions tests/python/test_pyintegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
19 changes: 19 additions & 0 deletions tests/test_astroid_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down

0 comments on commit 7fa3998

Please sign in to comment.