Fix an error in param comments

This commit is contained in:
Dave Halter
2018-03-14 09:53:25 +01:00
parent 13ba74515d
commit f5cf4c1954
2 changed files with 21 additions and 10 deletions

View File

@@ -80,7 +80,7 @@ def _fix_forward_reference(context, node):
return node return node
def _split_mypy_param_declaration(decl_text): def _split_comment_param_declaration(decl_text):
""" """
Split decl_text on commas, but group generic expressions Split decl_text on commas, but group generic expressions
together. together.
@@ -99,9 +99,14 @@ def _split_mypy_param_declaration(decl_text):
return [node.get_code().strip()] return [node.get_code().strip()]
params = [] params = []
for child in node.children: try:
if child.type in ['name', 'atom_expr', 'power']: children = node.children
params.append(child.get_code().strip()) except AttributeError:
return []
else:
for child in children:
if child.type in ['name', 'atom_expr', 'power']:
params.append(child.get_code().strip())
return params return params
@@ -128,7 +133,7 @@ def infer_param(execution_context, param):
match = re.match(r"^#\s*type:\s*\(([^#]*)\)\s*->", comment) match = re.match(r"^#\s*type:\s*\(([^#]*)\)\s*->", comment)
if not match: if not match:
return NO_CONTEXTS return NO_CONTEXTS
params_comments = _split_mypy_param_declaration(match.group(1)) params_comments = _split_comment_param_declaration(match.group(1))
# Find the specific param being investigated # Find the specific param being investigated
index = all_params.index(param) index = all_params.index(param)

View File

@@ -157,11 +157,6 @@ x = UNKNOWN_NAME2 # type: str
#? str() #? str()
x x
def x(a, b):
# type: ([) -> a
#?
a
class Cat(object): class Cat(object):
def __init__(self, age, friends, name): def __init__(self, age, friends, name):
# type: (int, List[Dog], str) -> None # type: (int, List[Dog], str) -> None
@@ -172,3 +167,14 @@ class Cat(object):
cat = Cat(UNKNOWN_NAME4, UNKNOWN_NAME5, UNKNOWN_NAME6) cat = Cat(UNKNOWN_NAME4, UNKNOWN_NAME5, UNKNOWN_NAME6)
#? str() #? str()
cat.name cat.name
# Check potential errors
def x(a, b):
# type: ([) -> a
#?
a
def x(a, b):
# type: (1) -> a
#?
a