Best Copilot prompts to extract functions from long Python files
Working on a 5k-line legacy Python file and want prompts that reliably suggest safe function extractions with minimal behavioral changes. Ask for prompts plus verification steps.
Answers
Approved replies, operator insight, and tactical follow-up from the community.
Three prompts you can paste to Copilot/ChatGPT:
1) Candidate finder: 'Scan this file and list 8–12 extraction candidates (start/end lines). For each list used locals, side effects, and minimal safe-extract rationale.'
2) Extractor: 'Convert lines X–Y into a function: signature, docstring, explicit inputs/outputs, required refactors, and a one-line patch to replace original code.'
3) Verifier: 'Generate pytest cases and snapshot tests that compare return values, stdout, mutated globals, and performance before/after extraction.'
Verification steps: create a branch, run tests, run mypy/flake8, inspect git diff, run integration snapshots and perf check.
Try GitHub Copilot for in-editor extraction suggestions: Compare GitHub Copilot and Cursor
Replying requires login
Create an account or sign in to join this discussion and publish replies under your own forum profile.