أوامر إعادة الهيكلة مع أقفال سلامة الأنواع
خطط الـ Migration، مش الـ Migration نفسه
لما التغيير بيمتد لأكتر من ملف أو أكتر من إصدار لغة، الحركة الصح إنك تطلب خطة الأول — مش الكود اللي اتهاجر. الخطة رخيصة في المراجعة. كود متهاجر منتشر في ملفات غالي في المراجعة وأغلى في التراجع.
ده مثال صغير Python 2 لـ 3.11:
Give me a 5-step migration plan to move this small Python 2 script to Python 3.11. Each step is one bullet. Then list 3 specific lines from the script that will break, with exact line content and the Python 3 replacement.
Script:
# inventory.py def report(items): print "Found %d items" % len(items) for i, item in items.iteritems(): print "%s: %s" % (i, item) if __name__ == "__main__": raw = raw_input("Path: ") print "Reading", raw
Claude Sonnet 4.5 رجّع:
# 5-Step Migration Plan
- Update all `print` statements to use `print()` function syntax with parentheses
- Replace `raw_input()` with `input()` for user input
- Change dictionary `.iteritems()` method to `.items()` (which returns an iterator in Python 3)
- Test the script with Python 3.11 interpreter to verify functionality
- Update the shebang line (if present) to point to Python 3.11 and consider adding type hints for modernization
# 3 Specific Breaking Lines
Line 3:
- Python 2: `print "Found %d items" % len(items)`
- Python 3: `print("Found %d items" % len(items))`
Line 5:
- Python 2: `for i, item in items.iteritems():`
- Python 3: `for i, item in items.items():`
Line 9:
- Python 2: `raw = raw_input("Path: ")`
- Python 3: `raw = input("Path: ")`
Captured from Claude Sonnet 4.5 (claude-sonnet-4-5) on 2026-04-27. Re-runs may differ slightly.
المخرج ورقة صفحة واحدة تقدر تستخدمها كـ checklist. كل خطوة PR لو عايز تقسّم. كل "breaking line" ادعاء تقدر تتحقّق منه — تقدر تـgrep على iteritems وتتأكد إن السكريبت فيه ظهور واحد بالظبط.
دلوقتي الـ migration الفعلية بتبقى prompt منفصل لكل خطوة:
Apply step 2 from the plan: replace
raw_inputwithinputininventory.py. Output a unified diff. Do not change anything else.
كل خطوة prompt صغير بـdiff صغير. كل diff قابل للمراجعة في 5 ثواني. لو خطوة باينة غلط، تتخطّاها من غير ما تخسر الباقي.
نمط plan-first شغّال في أي scale. لـ script صغير، الخطة 5 خطوات. لـ migration حقيقي (Python 2 لـ 3 على 50 ملف، أو React class components لـ hooks على الـ frontend كله)، الخطة بتبان بنفس الشكل — phases بدل steps، وكل phase بتبقى PR منفصل.
خطة migration بـ 5 خطوات على timeline:
Timeline ترحيل Python 2 → 3.11
كل print statements بتاخد أقواس؛ PR واحد، سهل الرجوع
تغيير استدعاءات قراءة الـ input؛ أصغر تحوّل دلالي
تغيير method الـ dict؛ المس كل loop
تأكد إن السلوك بيطابق baseline Python 2
ضيف type hints، ثبّت python_requires>=3.11
3 أنماط تنسخها من الـ prompt ده:
| النمط | بيعمل إيه |
|---|---|
| طلب الخطة AND الـ breaking lines | بيربط الخطوات المجرّدة بادعاءات تقدر تتحقّق منها |
| "Each step is one bullet" | بيجبر تغييرات atomic، مش فقرات |
| "Exact line content and replacement" | بتقدر تـgrep قبل ما تصدّق |
أمان مفيد: لما الخطة تدّعي "X سطور هيكسروا،" اعمل الـ grep. لو العدد غلط، الخطة جزئياً غلط، ولازم تعيد قبل ما تطبّق أي حاجة منها. الموديل سريع بس مش دايماً صح في اللي في codebase — هو بيشتغل من اللي لصقته بس.
التالي: إزاي تخلّي الموديل يكتب وصف الـ PR ليك. :::
سجّل الدخول للتقييم