refactor(types): auto -> None sweep across entire codebase
Applied 236 return type annotations to functions with no return values across 100+ files (core modules, tests, scripts, simulations). Added Phase 4 to python_style_refactor track for remaining 597 items (untyped params, vars, and functions with return values). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
56
scripts/scan_all_hints.py
Normal file
56
scripts/scan_all_hints.py
Normal file
@@ -0,0 +1,56 @@
|
||||
"""Scan all .py files for missing type hints. Writes scan_report.txt."""
|
||||
import ast, os
|
||||
|
||||
SKIP = {'.git', '__pycache__', '.venv', 'venv', 'node_modules', '.claude', '.gemini'}
|
||||
BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||
os.chdir(BASE)
|
||||
|
||||
results = {}
|
||||
for root, dirs, files in os.walk('.'):
|
||||
dirs[:] = [d for d in dirs if d not in SKIP]
|
||||
for f in files:
|
||||
if not f.endswith('.py'):
|
||||
continue
|
||||
path = os.path.join(root, f).replace('\\', '/')
|
||||
try:
|
||||
with open(path, 'r', encoding='utf-8-sig') as fh:
|
||||
tree = ast.parse(fh.read())
|
||||
except Exception:
|
||||
continue
|
||||
counts = [0, 0, 0] # nr, up, uv
|
||||
def scan(scope, prefix=''):
|
||||
for node in ast.iter_child_nodes(scope):
|
||||
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
||||
if node.returns is None:
|
||||
counts[0] += 1
|
||||
for arg in node.args.args:
|
||||
if arg.arg not in ('self', 'cls') and arg.annotation is None:
|
||||
counts[1] += 1
|
||||
if isinstance(node, ast.Assign):
|
||||
for t in node.targets:
|
||||
if isinstance(t, ast.Name):
|
||||
counts[2] += 1
|
||||
if isinstance(node, ast.ClassDef):
|
||||
scan(node, prefix=f'{node.name}.')
|
||||
scan(tree)
|
||||
nr, up, uv = counts
|
||||
total = nr + up + uv
|
||||
if total > 0:
|
||||
results[path] = (nr, up, uv, total)
|
||||
|
||||
lines = []
|
||||
lines.append(f'Files with untyped items: {len(results)}')
|
||||
lines.append('')
|
||||
lines.append(f'{"File":<58} {"NoRet":>6} {"Params":>7} {"Vars":>5} {"Total":>6}')
|
||||
lines.append('-' * 85)
|
||||
gt = 0
|
||||
for path in sorted(results, key=lambda x: results[x][3], reverse=True):
|
||||
nr, up, uv, t = results[path]
|
||||
lines.append(f'{path:<58} {nr:>6} {up:>7} {uv:>5} {t:>6}')
|
||||
gt += t
|
||||
lines.append('-' * 85)
|
||||
lines.append(f'{"TOTAL":<58} {"":>6} {"":>7} {"":>5} {gt:>6}')
|
||||
|
||||
report = '\n'.join(lines)
|
||||
with open('scan_report.txt', 'w', encoding='utf-8') as f:
|
||||
f.write(report)
|
||||
Reference in New Issue
Block a user