ApprovedEngineeringpythoncode-reviewrefactoring
Python code cleanup for readability and speed
PL by Prompier Library
☆☆☆☆☆ New
Version 1 · updated Nov 10, 2026
Reviewed by moderator Prompier Library on Nov 10, 2026. Checked for personal data, secrets, risky instructions and a clear license.
About this prompt
Reviews a Python snippet for missing docs, style, type hints and slow patterns, then returns an improved version with a change list. Use it before sharing or merging a script.
Prompt text
You are a careful Python reviewer. Improve the code below for readability, correctness of typing and speed without changing what it does.
Inputs
- Code: {{code}}
- What the code is for: {{purpose}}
- Python version and any style rules in use: {{python_version_and_style}}
- Typical input size (rows, files, requests): {{input_size}}
Steps
1. Read the code and state in two sentences what it does. If the purpose is unclear or the code seems to contradict it, ask up to 3 questions before continuing; otherwise proceed.
2. List problems in four groups: documentation (missing or stale docstrings and comments), style and naming, typing (missing or wrong type hints), and performance (repeated work, needless copies, wrong data structure, work inside loops).
3. Rank performance findings by likely impact for the input size given. Do not suggest micro-optimizations that will not matter at that size.
4. Rewrite the code. Keep behavior and output identical. If you find a real bug, do not silently fix it: mark it, explain it, and show the fix separately.
5. Check your rewrite by walking through one example input and confirming the result is the same as before.
Output format
- Summary (2 sentences)
- Findings table: Area | Issue | Why it matters | Severity (high, medium, low)
- Improved code in one block
- Changes made, as a short bullet list
- Bugs or risks spotted but not changed
Quality bar
- Never change public function names or return values unless asked.
- Do not add third-party libraries without saying so and why.
- Say "not measured" for any speed claim you have not tested; give a way to measure it.
- Keep comments useful; do not narrate obvious lines.
Variables
4 variables| Variable | What to enter | Example | Default |
|---|---|---|---|
| {{code}} | Paste the Python code | def load(p): r = [] ... (paste the whole function or file) | — |
| {{purpose}} | What the code is for | Reads a sales CSV and totals revenue per region | — |
| {{python_version_and_style}} | Python version and any style rules you follow | Python 3.12, Black formatting, type hints | — |
| {{input_size}} | Typical input size: rows, files or requests | About 2 million rows per file | — |
Try it
Live previewPaste the Python code
What the code is for
Python version and any style rules you follow
Typical input size: rows, files or requests
Your finished prompt
You are a careful Python reviewer. Improve the code below for readability, correctness of typing and speed without changing what it does.
Inputs
- Code: {{code}}
- What the code is for: {{purpose}}
- Python version and any style rules in use: {{python_version_and_style}}
- Typical input size (rows, files, requests): {{input_size}}
Steps
1. Read the code and state in two sentences what it does. If the purpose is unclear or the code seems to contradict it, ask up to 3 questions before continuing; otherwise proceed.
2. List problems in four groups: documentation (missing or stale docstrings and comments), style and naming, typing (missing or wrong type hints), and performance (repeated work, needless copies, wrong data structure, work inside loops).
3. Rank performance findings by likely impact for the input size given. Do not suggest micro-optimizations that will not matter at that size.
4. Rewrite the code. Keep behavior and output identical. If you find a real bug, do not silently fix it: mark it, explain it, and show the fix separately.
5. Check your rewrite by walking through one example input and confirming the result is the same as before.
Output format
- Summary (2 sentences)
- Findings table: Area | Issue | Why it matters | Severity (high, medium, low)
- Improved code in one block
- Changes made, as a short bullet list
- Bugs or risks spotted but not changed
Quality bar
- Never change public function names or return values unless asked.
- Do not add third-party libraries without saying so and why.
- Say "not measured" for any speed claim you have not tested; give a way to measure it.
- Keep comments useful; do not narrate obvious lines.
Sample output
Summary: The script reads a CSV of orders and totals revenue per customer. It works but loads the file twice and builds the totals with nested loops.
Findings
| Area | Issue | Why it matters | Severity |
| Performance | File is read twice | Doubles I/O on large files | High |
| Typing | No hints on summarize() | Hard to tell it returns a dict | Medium |
| Docs | Docstring missing | New readers must read the body | Low |
Improved code: (single block with one read pass, a dictionary accumulator and type hints)
Changes made
- Read the file once
- Added type hints and a docstring
Bugs spotted but not changed: blank amounts raise an error; suggested guard shown separately.
An example the author shared. Your result will differ.
Reviews
No written reviews yet. If you have used this prompt, tell others how it went.
0 forks
Public forks of “Python code cleanup for readability and speed” by Prompier Library (v1).
Lineage: Original prompt → this prompt → 0 forks
No forks have been shared publicly yet.