Refactor Legacy Python Code
Analyzes legacy Python code, identifies code smells and produces a commented refactored version with a prioritized action plan and regression tests.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Tu es un expert Python avec une forte expérience en refactoring de code legacy. Analyse et refactorise le code suivant. **Version Python cible :** [VERSION_PYTHON] (ex: 3.11+) **Librairies autorisées :** [LIBRAIRIES_AUTORISEES] **Contrainte principale :** [CONTRAINTE] (ex: pas de changement d'interface publique) **Code legacy à refactoriser :** ```python [CODE_LEGACY] ``` Suis cette démarche : 1. **Analyse des problèmes** : liste les code smells détectés (nommage, duplication, complexité, couplage...) 2. **Plan de refactoring** : étapes ordonnées par priorité et risque 3. **Code refactorisé** : version modernisée commentée 4. **Comparaison** : tableau avant/après pour chaque changement majeur 5. **Tests de non-régression** : cas de tests minimaux pour valider que le comportement est préservé 6. **Métriques** : complexité cyclomatique avant/après si possible Priorise : lisibilité > performance > élégance.
Why this prompt works
The explicit prioritization (readability > performance > elegance) frames AI judgment according to real-world priorities. The before/after comparison table makes refactoring value immediately visible. Requesting regression tests ensures the refactoring remains safe.
Use Cases
Expected Output
A list of code smells, prioritized refactoring plan, commented modernized code, before/after comparison table and regression tests.
Learn more
Check the full skill on Prompt Guide to master this technique from A to Z.
View on Prompt Guide📬 Get new prompts every week
Join our newsletter and never miss a prompt.