Automated Python code reviewer combining AST-based static analysis, regex pattern detection, and optional LLM-powered feedback.
Security
- Hardcoded passwords, API keys, tokens
eval()/exec()usage
Bugs
- Bare
except:clauses (catches KeyboardInterrupt) - Mutable default arguments (
def foo(x=[])) - Silent error swallowing (
except: pass)
Style
- Wildcard imports (
from x import *) - TODO/FIXME comments
- Commented-out code blocks
from ai_reviewer import CodeReviewer
reviewer = CodeReviewer()
result = reviewer.review(open("app.py").read(), "app.py")
print(result.summary())
# Review: app.py
# 5 issues (2 errors, 1 warnings)
# security: 2
# bug: 1
# style: 2
for issue in result.issues:
print(f" {issue}")
if issue.suggestion:
print(f" -> {issue.suggestion}")def llm_review(code, filename):
# call your LLM API here
return client.chat("Review this code for issues:\n" + code)
reviewer = CodeReviewer(llm_review_fn=llm_review)
result = reviewer.review(code)
print(result.llm_feedback)# skip style issues, only show warnings and errors
reviewer = CodeReviewer(
skip_categories={"style"},
min_severity="warning",
)pytest -v