32

When running pylint on a python file it shows me warnings regarding TODO comments by default. E.g.:

************* Module foo
W:200, 0: TODO(SE): fix this! (fixme)
W:294, 0: TODO(SE): backlog item (fixme)
W:412, 0: TODO(SE): Delete bucket? (fixme)

While I do find this behavior useful, I would like to know of a way of temporarily and/or permanently turn these specific warnings on or off.

I am able to generate a pylint config file: pylint --generate-rcfile > ~/.pylintrc

I'm just note sure what to put in this file to disable warnings for TODO comments.

sedwards
  • 427
  • 1
  • 5
  • 4

4 Answers4

47

in the generated config file, you should see a section

  [MISCELLANEOUS]

  # List of note tags to take in consideration, separated by a comma.
  notes=FIXME,XXX,TODO

simply drop TODO from the "notes" list.

The config file is found at

~/.pylintrc

If you have not generated the config file, this can be done with

pylint --generate-rcfile > ~/.pylintrc
Thomas Crowley
  • 988
  • 2
  • 8
  • 23
sthenault
  • 14,397
  • 5
  • 38
  • 32
  • Todo seems like a cool feature with pylint. Is it possible to have a "todo" block instead of a single line? Thanks. – ScipioAfricanus Nov 06 '19 at 22:40
  • This feels like a very wrong way to disable it temporarily as you can't check if new TODOs were added or removed. captainblack's answer looks more correct – Eugene K Dec 07 '20 at 19:11
  • Is there a way to do the same using the VS Code settings for pylint rather than a .pylintrc file ? – vianmixt Oct 21 '21 at 15:25
  • @vianmixt If you are using VS Code, pass this argument then: `--disable=fixme`. – Rafs Dec 21 '22 at 11:24
12

Along with the solution posted by @sthenault where you could disable all warnings, Pylint also allows you to ignore a single line (helpful if you would want to deal with it in the future) like so:

A_CONSTANT = 'ugh.'  # TODO: update value  # pylint: disable=fixme

or by stating the Rule ID:

A_CONSTANT = 'ugh.'  # TODO: update value  # pylint: disable=W0511
captainblack
  • 4,107
  • 5
  • 50
  • 60
  • Note that if your `# TODO` comment starts at the start of a line (i.e. it's a block comment rather than an inline comment, even if only a single line), adding `# pyline: disable=fixme` to the same line will disable the fixme rule for the whole scope (e.g. function). I don't think there a way to tell pylint to ignore a single TODO comment in a block comment. – Stu Cox Jun 16 '21 at 13:42
1

IMHO your code should not have # TODO but during development it might be needed to have TODO for a short period of time and in this case pylint will bother you. To avoid this during this time the best is to globally disable it in the pylintrc by adding fixme to the disable list like this:

[MESSAGES CONTROL]
# globally disable pylint checks (comma separated)
disable=fixme,...

So it let you the time to fix all your TODO and once this is done, you can remove the fixme from the pylintrc. Note if you use an older pylint version you will need to use W0511 instead of fixme. For more detail see https://pylint.pycqa.org/en/stable/technical_reference/features.html#messages-control-options

Changing the pylintrc notes as proposed in the first answer is a bad practice in my opinion. notes is designed to configure wich comments triggers the fixme warning and not designed to disable the warning.

Brice.S
  • 47
  • 6
0

In our projects we have a pylint.cfg file. We use the --rcfile pylint option to point to that file.

In pylint.cfg, I can disable checker W0511, which is the checker that complains about "TODO" and similar terms in comments. Just add W0511 to the comma-separated list for parameter disable.

But remember that, as Uncle Bob Martin says, a TODO is not an excuse to leave bad code in the system, and the code should be scanned regularly to remove TODOs, and pylint and/or sonarqube issues can work as good reminders and motivation for doing so.

Paulo Merson
  • 13,270
  • 8
  • 79
  • 72