0

Is it possible to ignore one single specific line with pylint? has solutions that requires littering source code with comments what is undesirable for me.

Is there way to specify that given instance is false positive in arguments of the pylint command line tool?

reducing activity
  • 1,985
  • 2
  • 36
  • 64
  • 1
    I don't think it is possible to ignore a specific line without changing the source code. However, it is certainly possible to ignore warning types in the `.pylintrc`. Do you have a specific case in mind? – Scott Skiles Jan 28 '19 at 15:43
  • @ScottSkiles I have a repository with simple programs, each in multiple stages - from simplest possible to final one with more features. I use it during teaching programming. In this specific case I want to suppress one instance of `W0612: Unused variable 'i' (unused-variable)` as it becomes used one step later and it makes no sense to switch from `_` variable name to `i` variable name just to pacify validator. And adding magic comment is unwanted as confusing beginners by weird comments is undesirable. – reducing activity Jan 28 '19 at 15:56
  • I opened issue at github: https://github.com/PyCQA/pylint/issues/2712 – reducing activity Jan 29 '19 at 08:31
  • Ok. Just off the top of my head that might be very difficult to do without any modifications to the source code... have you thought about how this might be implemented? – Scott Skiles Jan 29 '19 at 14:33

1 Answers1

2

I don't think it is possible to ignore a specific line without changing the source code. However, it is certainly possible to ignore warning types in the .pylintrc or at the top of file.

I'd go with the approach of creating a .pylintrc to suit your needs. For example, if you want to completely ignore W0612: unused-variable then you can create a .pylintrc file and add message names to disable as noted in pytest docs.

.pylintrc

disable=unused-variable,
..., 

Alternatively, you can disable messages on a case by case basis at the top of the file, and just tell your students to ignore it:

Top of file

# pylint: disable=unused-variable, wildcard-import, method-hidden
# pylint: enable=too-many-lines
Scott Skiles
  • 3,647
  • 6
  • 40
  • 64
  • Is it possible to ignore given warning just in one file? I want to get rid of just a single false positive, this rule generally makes sense? – reducing activity Jan 28 '19 at 19:32
  • I don't think so. If it is just a single line, I think it is safe to just add it and tell your students to ignore it... – Scott Skiles Jan 28 '19 at 20:13