Skip to content

Commit 0e39d43

Browse files
committed
Merged extract_types into extract_pyi
1 parent 416da44 commit 0e39d43

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

tools/extract_pyi.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,29 @@
5353
# Validate that the module is a parseable stub.
5454
total += 1
5555
try:
56-
astroid.parse(stub_contents)
56+
tree = astroid.parse(stub_contents)
57+
for i in tree.body:
58+
print(i.__dict__['name'])
59+
for j in i.body:
60+
if isinstance(j, astroid.scoped_nodes.FunctionDef):
61+
a = ''
62+
if None in j.args.__dict__['annotations']:
63+
a += f"Missing parameter type: {j.__dict__['name']} on line {j.__dict__['lineno']}\n"
64+
if j.returns:
65+
if 'Any' in j.returns.__dict__.values():
66+
a += f"Missing return type: {j.__dict__['name']} on line {j.__dict__['lineno']}"
67+
if a:
68+
raise TypeError(a)
69+
elif isinstance(j, astroid.node_classes.AnnAssign):
70+
if 'Any' == j.__dict__['annotation'].__dict__['name']:
71+
raise TypeError(f"missing attribute type on line {j.__dict__['lineno']}")
72+
5773
ok += 1
5874
except astroid.exceptions.AstroidSyntaxError as e:
5975
e = e.__cause__
6076
traceback.print_exception(type(e), e, e.__traceback__)
61-
print()
77+
except TypeError as err:
78+
print(err)
6279

6380
print(f"{ok} ok out of {total}")
6481

0 commit comments

Comments
 (0)