Skip to content

PyCharm Usage

Brendan Maginnis edited this page Jun 27, 2020 · 11 revisions

How does it work?

Sourcery scans the currently open Python file. If it finds improvements in your code it returns them as a list of refactorings. You can see these in the editor as highlighted sections of code.

How do I see all the refactorings?

The refactorings appear in the Sourcery tool window (which appears at the bottom of the screen). You can click on each refactoring to scroll to it. To see a diff of the suggested changes, click on the arrow next to it in the tool window to expand it.

How do I apply a refactoring?

There are 3 options:

  1. Press Alt+Enter on the suggested refactoring and apply the refactoring
  2. Hover the mouse over the refactoring and a lightbulb will appear. Click the lightbulb and apply the refactoring.
  3. Right click on the suggested refactoring in the Sourcery window and select the Refactor function option

How do I configure Sourcery?

You can configure Sourcery to ignore certain files or folders in your project. Please see the Sourcery configuration section for details.

How do I disable Sourcery refactorings?

Please see disable refactorings on how to do this. The PyCharm plugin has shortcuts to adds these comments automatically.

How do I refactor my whole project?

The Sourcery plugins can only currently refactor one file at a time.

If you have the Sourcery GitHub Bot installed you can request to refactor a whole repo from the sourcery website dashboard.

Clone this wiki locally