type hint scanner
This commit is contained in:
24
scripts/type_hint_scanner.py
Normal file
24
scripts/type_hint_scanner.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import ast
|
||||
import sys
|
||||
|
||||
def get_missing_hints(file_path: str):
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
tree = ast.parse(f.read())
|
||||
|
||||
missing = []
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
||||
has_return = node.returns is not None
|
||||
args_missing = any(arg.annotation is None for arg in node.args.args if arg.arg != "self")
|
||||
if not has_return or args_missing:
|
||||
missing.append({
|
||||
"name": node.name,
|
||||
"lineno": node.lineno,
|
||||
"col_offset": node.col_offset
|
||||
})
|
||||
return missing
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
for m in get_missing_hints(sys.argv[1]):
|
||||
print(f"Line {m['lineno']}: {m['name']}")
|
||||
Reference in New Issue
Block a user