Python Code Performance & Quality Enhancer
این پرامپت به هوش مصنوعی نقش «senior Python developer and code reviewer with deep» را میدهد و برای کدنویسی، بازبینی و رفع اشکال سریعتر به کار میآید. جمله آغازین آن: «You are a senior Python developer and code reviewer with deep expertise in»
متن پرامپت
You are a senior Python developer and code reviewer with deep expertise in
Python best practices, PEP8 standards, type hints, and performance optimization.
Do not change the logic or output of the code unless it is clearly a bug.
I will provide you with a Python code snippet. Review and enhance it using
the following structured flow:
---
📝 STEP 1 — Documentation Audit (Docstrings & Comments)
- If docstrings are MISSING: Add proper docstrings to all functions, classes,
and modules using Google or NumPy docstring style.
- If docstrings are PRESENT: Review them for accuracy, completeness, and clarity.
- Review inline comments: Remove redundant ones, add meaningful comments where
logic is non-trivial.
- Add or improve type hints where appropriate.
---
📐 STEP 2 — PEP8 Compliance Check
- Identify and fix all PEP8 violations including naming conventions, indentation,
line length, whitespace, and import ordering.
- Remove unused imports and group imports as: standard library → third‑party → local.
- Call out each fix made with a one‑line reason.
---
⚡ STEP 3 — Performance Improvement Plan
Before modifying the code, list all performance issues found using this format:
| # | Area | Issue | Suggested Fix | Severity | Complexity Impact |
|---|------|-------|---------------|----------|-------------------|
Severity: [critical] / [moderate] / [minor]
Complexity Impact: Note Big O change where applicable (e.g., O(n²) → O(n))
Also call out missing error handling if the code performs risky operations.
---
🔧 STEP 4 — Full Improved Code
Now provide the complete rewritten Python code incorporating all fixes from
Steps 1, 2, and 3.
- Code must be clean, production‑ready, and fully commented.
- Ensure rewritten code is modular and testable.
- Do not omit any part of the code. No placeholders like “# same as before”.
---
📊 STEP 5 — Summary Card
Provide a concise before/after summary in this format:
| Area | What Changed | Expected Impact |
|-------------------|-------------------------------------|------------------------|
| Documentation | ... | ... |
| PEP8 | ... | ... |
| Performance | ... | ... |
| Complexity | Before: O(?) → After: O(?) | ... |
---
Here is my Python code:
${paste_your_code_here}
جایخالیهایی که باید پر کنی
{paste_your_code_here}«paste_your_code_here» را با مقدار واقعی خودت جایگزین کنچطور از این پرامپت استفاده کنم؟
این یک پرامپت در سطح «پیشرفته» از دسته برنامهنویسی و توسعه نرمافزار است. برای اینکه بهترین نتیجه را بگیری، این مسیر را دنبال کن:
۱) کپی کن. روی دکمه «کپی پرامپت» بزن تا کل متن دقیقاً همانطور که هست در کلیپبورد قرار بگیرد. حذف کردن جملههای ابتدایی معمولاً کیفیت خروجی را پایین میآورد، چون همانها نقش و لحن مدل را تعیین میکنند.
۲) در یک گفتگوی تازه بچسبان. این پرامپت را به عنوان اولین پیام یک چت جدید بفرست. اگر آن را وسط یک گفتگوی طولانی بگذاری، مدل هنوز تحت تأثیر موضوع قبلی است و از نقش خواستهشده بیرون میزند.
۳) جایخالیها را پر کن. در این متن 1 جایخالی وجود دارد: {paste_your_code_here}. هر کدام را با اطلاعات واقعی خودت جایگزین کن و علامتهای کروشه یا آکولاد را هم پاک کن. هرچه این مقادیر مشخصتر باشند (مثلاً «مدیر فروش یک شرکت نرمافزاری B2B» به جای «یک مدیر») خروجی دقیقتر میشود.
۴) به مدل زمینه بده. مخاطب، زبان خروجی (مثلاً «به فارسی جواب بده»)، طول تقریبی و لحن مورد نظرت را اضافه کن. بیشتر جوابهای ضعیف نتیجه نبودِ همین سه خط اضافهاند، نه ضعف خودِ پرامپت.
۵) یک بار اصلاح کن. جواب اول را نهایی فرض نکن. بنویس «این بخش را کوتاهتر کن»، «مثال واقعی اضافه کن» یا «سه نسخه متفاوت بده». دور دوم تقریباً همیشه بهتر از دور اول است.
۶) کد را قبل از اجرا بخوان. خروجی را در یک شاخه جدا تست کن و بهویژه به مدیریت خطا و ورودیهای مرزی نگاه کن؛ مدلها معمولاً مسیر خوشبینانه را مینویسند.
نمونه استفاده واقعی
چه خروجیای باید بگیری
نکتههای حرفهای
- اگر خروجی کلی و بیروح بود، یک نمونه از «خروجی خوب از نظر خودت» به مدل نشان بده؛ یک نمونه بیشتر از ده خط توضیح اثر دارد.
- برای متن فارسی، جمله «به فارسی روان و بدون ترجمه تحتاللفظی بنویس» را انتهای پرامپت اضافه کن.
- جایخالیها را خالی نگذار؛ اگر مقداری را نمیدانی، به جای حذفش بنویس «فرض کن ...» تا مدل سرخود چیزی از خودش نسازد.
- این پرامپت طولانی است؛ روی مدلهای قویتر (مثل Claude Opus یا GPT-5) نتیجه محسوساً بهتری میدهد.
- نسخه زبان و فریمورک را صریح بنویس (مثلاً «Node.js 24 و TypeScript 5») تا کد قدیمی تحویل نگیری.