Fix separated type comments for arguments not merging correctly in Python 3.7

pull/394/head
Ashley Whetter 1 year ago
parent 434ef8305a
commit 7fa3998438

@ -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

@ -0,0 +1 @@
Fix separated type comments for arguments not merging correctly in Python 3.7

@ -355,9 +355,7 @@ class TestPy3Module:
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 @@ class TestAnnotationCommentsModule:
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")

@ -163,6 +163,25 @@ class TestAstroidUtils:
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",
[

Loading…
Cancel
Save