Better keyerror handling

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

View File

@ -54,6 +54,7 @@ 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:
if 'name' in i.__dict__:
print(i.__dict__['name']) print(i.__dict__['name'])
for j in i.body: for j in i.body:
if isinstance(j, astroid.scoped_nodes.FunctionDef): if isinstance(j, astroid.scoped_nodes.FunctionDef):
@ -63,15 +64,14 @@ def convert_folder(top_level, stub_directory):
if 'Any' in j.returns.__dict__.values(): if 'Any' in j.returns.__dict__.values():
print(f"Missing return type: {j.__dict__['name']} on line {j.__dict__['lineno']}") print(f"Missing return type: {j.__dict__['name']} on line {j.__dict__['lineno']}")
elif isinstance(j, astroid.node_classes.AnnAssign): elif isinstance(j, astroid.node_classes.AnnAssign):
if 'Any' == j.__dict__['annotation'].__dict__['name']: if 'name' in j.__dict__['annotation'].__dict__:
if j.__dict__['annotation'].__dict__['name'] == 'Any':
print(f"missing attribute type on line {j.__dict__['lineno']}") 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