Files

39 lines
1.4 KiB
Python

"""Scan chunker.py for code smells: unused args, redundant conditions."""
import ast
with open("/root/.hermes/wizard-outputs/forge/chunker.py") as f:
src = f.read()
lines = src.splitlines()
tree = ast.parse(src)
for node in ast.walk(tree):
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
arg_names = [a.arg for a in node.args.args]
for arg in node.args.args:
if arg.arg == "self":
continue
used = False
for n in ast.walk(node):
if isinstance(n, ast.Name) and n.id == arg.arg:
used = True
break
if isinstance(n, ast.Attribute) and n.attr == arg.arg:
used = True
break
if not used:
print(f"UNUSED ARG: func={node.name} arg={arg.arg} line={node.lineno}")
# Check for the 'if end >= n: break' pattern in _hard_split_long
print("\n--- Checking _hard_split_long for redundant break ---")
for i, line in enumerate(lines, 1):
if "end >= n" in line or "end >= n:" in line:
print(f"Line {i}: {line.strip()}")
# Check reconstruct for unused overlap_tokens
print("\n--- Checking reconstruct body for overlap_tokens usage ---")
reconstruct_src = "\n".join(lines[240:280]) # rough
for i, line in enumerate(lines, 1):
if "overlap_tokens" in line and 241 <= i <= 280:
print(f"Line {i}: {line.strip()}")