Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I format a multi-line TODO comment in PyCharm?

I want to add a multi-line TODO comment to my PyCharm project.

# TODO: Multiple errors can be wrapped inside an exception.
#       WfcApiException should do recursive error checking to locate
#       and store an arbitrary number of nested errors.

Unfortunately, PyCharm only recognizes the first line as a TODO comment. Any following lines are viewed as standard Python comments.

Failed attempt at a multi-line TODO statement in PyCharm

What is the correct way to format a multi-line TODO comment in PyCharm?

like image 790
Stevoisiak Avatar asked Feb 06 '18 15:02

Stevoisiak


People also ask

How do you comment multiple lines in PyCharm?

Comment out multiple lines in Pycharm If we have to comment out multiple lines of code in Pycharm, we can select the lines to be commented out and then press ctrl+shift+/ .

How do you add a TODO comment in PyCharm?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | TODO. Use a regular expression to specify a custom pattern. This matches the word "optimize" ( \b designates word boundaries) and allows any number of other characters in the comment. Then click OK to save the new pattern.

How do you add a TODO comment in Python?

Place the caret where you want to create a TODO item and add a comment, for example, by pressing Ctrl+/ , then type TODO or FIXME , and then type your note.

How do you comment out a block of code in PyCharm?

To comment a line of code, place the caret at the appropriate line and press Ctrl+/ . Press Ctrl+/ again on the same line to uncomment it. To move a line up or down, press Alt+Shift+Up or Alt+Shift+Down respectively.


2 Answers

Pycharm 2018.3 does support multiline todo, yay!

https://youtu.be/5gJ7_3wCfUk?t=65

https://blog.jetbrains.com/pycharm/2018/11/pycharm-2018-3-out-now/

So, using your TODO comment:

# TODO: Multiple errors can be wrapped inside an exception.
#       WfcApiException should do recursive error checking to locate
#       and store an arbitrary number of nested errors.

yields:

enter image description here

Actually, you only need to indent the following lines one character to the right of the TODO so this would be just on the limit from being detected:

enter image description here

And the todo is captured as a single item, of course:

enter image description here

like image 149
payala Avatar answered Oct 16 '22 09:10

payala


Update: It appears JetBrains added this feature, see payala's answer

PyCharm does not support multi-line TODOs, one alternative option would be to use a multi line string

'''
TODO foobar
foobar
'''

This won't have the TODO highlighting like # TODO foo, but it will stand out from the rest of your code with the string highlighting.

You could also try

# TODO -----------------
# TODO  foobar this
# TODO  comment 
# TODO  comment
# TODO  comment
# TODO ------------------

If you have a particularly chunky and important TODO note.

like image 21
bphi Avatar answered Oct 16 '22 09:10

bphi