Skill library / Cursor

Python Refactoring skill for Cursor

Refactoring is only safe when behaviour stays identical. This skill makes Cursor improve Python code in small, verifiable steps with type hints and tests as a safety net.

Customise this skill free →

What it's good for

How the skill works

  1. Run existing tests (or write characterisation tests first)
  2. Add type hints to public functions
  3. Extract long functions into well-named helpers
  4. Remove duplication and dead code
  5. Re-run tests and summarise each change

Built-in rules

Example

You: “Refactor process_orders.py”
Result: 4 extracted functions, full type hints, a removed duplicate loop, and all 12 tests still passing.

SKILL.md template

Save as python-refactoring/SKILL.md.

---
name: python-refactoring
description: "Refactors Python code for readability and maintainability, adding type hints, splitting long functions and removing duplication without changing behaviour. Use when the user asks to clean up, refactor or modernise Python code."
---

# Python Refactoring

## Workflow
1. Run existing tests (or write characterisation tests first)
2. Add type hints to public functions
3. Extract long functions into well-named helpers
4. Remove duplication and dead code
5. Re-run tests and summarise each change

## Rules
- Don't change behaviour or public interfaces without asking
- Follow PEP 8 and the project's formatter
- Prefer standard library over new dependencies

How to install in Cursor

Put the folder in .cursor/skills/ (or .agents/skills/), or copy the included .mdc file into .cursor/rules/.

Pro tip

Set globs to **/*.py and mention your Python version so it uses the right syntax features.

Want it tailored to how you work?

Answer a few questions and get a customised version with examples, a Cursor rule and GPT/Gem instructions, emailed free.

Make my version →

FAQ

How do I install the python refactoring skill in Cursor?

Put the folder in .cursor/skills/ (or .agents/skills/), or copy the included .mdc file into .cursor/rules/.

Is it free?

Yes. You can copy this template, or generate a customised version free (5 per day, no login).

Does it work on other platforms?

Yes. The SKILL.md follows the open Agent Skills standard, and every generated package also includes a Cursor rule and ChatGPT/Gemini instructions.

Related skills