Better keyerror handling

This commit is contained in:
dherrada 2020-05-27 11:30:51 -04:00
parent 67cb48acbf
commit 4e22b9a346

View File

@ -54,24 +54,24 @@ def convert_folder(top_level, stub_directory):
try: try:
tree = astroid.parse(stub_contents) tree = astroid.parse(stub_contents)
for i in tree.body: for i in tree.body:
print(i.__dict__['name']) if 'name' in i.__dict__:
for j in i.body: print(i.__dict__['name'])
if isinstance(j, astroid.scoped_nodes.FunctionDef): for j in i.body:
if None in j.args.__dict__['annotations']: if isinstance(j, astroid.scoped_nodes.FunctionDef):
print(f"Missing parameter type: {j.__dict__['name']} on line {j.__dict__['lineno']}\n") if None in j.args.__dict__['annotations']:
if j.returns: print(f"Missing parameter type: {j.__dict__['name']} on line {j.__dict__['lineno']}\n")
if 'Any' in j.returns.__dict__.values(): if j.returns:
print(f"Missing return type: {j.__dict__['name']} on line {j.__dict__['lineno']}") if 'Any' in j.returns.__dict__.values():
elif isinstance(j, astroid.node_classes.AnnAssign): print(f"Missing return type: {j.__dict__['name']} on line {j.__dict__['lineno']}")
if 'Any' == j.__dict__['annotation'].__dict__['name']: elif isinstance(j, astroid.node_classes.AnnAssign):
print(f"missing attribute type on line {j.__dict__['lineno']}") if 'name' in j.__dict__['annotation'].__dict__:
if j.__dict__['annotation'].__dict__['name'] == 'Any':
print(f"missing attribute type on line {j.__dict__['lineno']}")
ok += 1 ok += 1
except astroid.exceptions.AstroidSyntaxError as e: except astroid.exceptions.AstroidSyntaxError as e:
e = e.__cause__ e = e.__cause__
traceback.print_exception(type(e), e, e.__traceback__) traceback.print_exception(type(e), e, e.__traceback__)
except KeyError:
print("Function does not have a key: Name")
print() print()
return ok, total return ok, total