PyCharm 2018.3 Help

TODO comments

Sometimes, you need to mark parts of your code for future reference: areas of optimization and improvement, possible changes, questions to be discussed, and so on. PyCharm lets you add special types of comments that are highlighted in the editor, indexed, and listed in the TODO Tool Window. This way you and your teammates can keep track of issues that require attention.

TODO comments example

By default, there are two patterns recognized by PyCharm: TODO and FIXME in both lower and upper case. These patterns can be used inside line and block comments of any supported file type. You can modify the default patterns or add your own patterns if necessary.

To create a multiline TODO item, indent the comment lines that follow the initial line. Without the indent, lines are treated as regular comment lines. To disable multiline TODO items, open the Settings / Preferences dialog (Ctrl+Alt+S), then go to Editor | TODO and clear the Treat the indented text on the following lines as part of the same TODO checkbox.

TODO comments example

To view TODO items, open the TODO tool window: View | Tool Windows | TODO or Alt+6.

The TODO tool window

To jump to a TODO comment in the source code, click the corresponding TODO item in the TODO tool window. To disable this behavior, right-click the TODO tool window title bar, point to View Options, and clear the Autoscroll to Source option (in this case, you will need to double-click the TODO item to jump to the relevant comment).

Add custom patterns and filter TODO items

You can add your own patterns and filter the list to show only TODO items that match certain patterns. For example, you can choose to mark places of possible optimization in your code with the OPTIMIZE pattern and ignore all other types of TODO items when viewing them in the TODO tool window:

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Editor | TODO.

  2. To add a pattern for the OPTIMIZE items, click the Add icon (Add) in the Patterns section of the TODO dialog, and type the following pattern:

    \boptimize\b.*

    Then click OK to save the new pattern.

  3. To add a filter with the new pattern, click the Add icon (Add) in the Filters section of the TODO dialog, specify a name for the new filter (for example, Optimization), and select the new pattern to be included in this filter.

    Then click OK to save the new filter.

  4. Click OK to apply the changes in the TODO settings dialog.

  5. To apply the new filter, in the TODO tool window, click the Filter TODO Items icon (Filter TODO Items) and select the Optimization filter.

Last modified: 27 February 2019