Skip to content

Commit 4e22b9a

Browse files
author
dherrada
committed
Better keyerror handling
1 parent 67cb48a commit 4e22b9a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

tools/extract_pyi.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,24 @@ def convert_folder(top_level, stub_directory):
5454
try:
5555
tree = astroid.parse(stub_contents)
5656
for i in tree.body:
57-
print(i.__dict__['name'])
58-
for j in i.body:
59-
if isinstance(j, astroid.scoped_nodes.FunctionDef):
60-
if None in j.args.__dict__['annotations']:
61-
print(f"Missing parameter type: {j.__dict__['name']} on line {j.__dict__['lineno']}\n")
62-
if j.returns:
63-
if 'Any' in j.returns.__dict__.values():
64-
print(f"Missing return type: {j.__dict__['name']} on line {j.__dict__['lineno']}")
65-
elif isinstance(j, astroid.node_classes.AnnAssign):
66-
if 'Any' == j.__dict__['annotation'].__dict__['name']:
67-
print(f"missing attribute type on line {j.__dict__['lineno']}")
57+
if 'name' in i.__dict__:
58+
print(i.__dict__['name'])
59+
for j in i.body:
60+
if isinstance(j, astroid.scoped_nodes.FunctionDef):
61+
if None in j.args.__dict__['annotations']:
62+
print(f"Missing parameter type: {j.__dict__['name']} on line {j.__dict__['lineno']}\n")
63+
if j.returns:
64+
if 'Any' in j.returns.__dict__.values():
65+
print(f"Missing return type: {j.__dict__['name']} on line {j.__dict__['lineno']}")
66+
elif isinstance(j, astroid.node_classes.AnnAssign):
67+
if 'name' in j.__dict__['annotation'].__dict__:
68+
if j.__dict__['annotation'].__dict__['name'] == 'Any':
69+
print(f"missing attribute type on line {j.__dict__['lineno']}")
6870

6971
ok += 1
7072
except astroid.exceptions.AstroidSyntaxError as e:
7173
e = e.__cause__
7274
traceback.print_exception(type(e), e, e.__traceback__)
73-
except KeyError:
74-
print("Function does not have a key: Name")
7575
print()
7676
return ok, total
7777

0 commit comments

Comments
 (0)