drakenation
drakenation

Reputation: 412

Is it possible to partially disable a pylint rule based on its message?

Some rules are used in more than a single situation. In particular, the rule C0326 is employed in at least 2 situations:

def func() : 
    pass

gives the message C0326:No space allowed before :

def func(param:int):
    pass

gives the message C0326:Exactly one space required after :

I want pylint to detect and complain about the first case, but not the second (yes, I know I'm a barbarian for not placing a space before the type hint) one. Since the code is the same but messages are different, I'm hopeful that it's possible to adjust these cases individually. Is it currently possible to do that?

Upvotes: 2

Views: 303

Answers (1)

davidlowryduda
davidlowryduda

Reputation: 2559

No, this isn't possible. Or rather, it's not possible without changing pylint's internals.

It may be that the easiest way to produce only the errors you want while still having barbaric whitespace practices would be to add a pylint-disabling comment on the relevant lines. As an example, consider the following sample file.

def fun(x) :  #pylint: disable=bad-whitespace
    return

def fun2(x:int):
    return 2 * x

Pylint will complain about the bad-whitespace in fun2, but not fun1.

Upvotes: 1

Related Questions