How to disable "No space allowed around keyword argument assignment" in Pylint?
I found why it checks for the spaces (PEP 8, why no spaces around '=' in keyword argument or a default parameter value?), but I don't agree because this means I need to spend hours of solving only this message.
I looked for the message so I can disable it in the rcfile here: http://pylint-messages.wikidot.com/all-codes But the message does not appear in the pylint documentation?!
This can be disabled in Pylint with bad-whitespace
:
$ cat a.py
myfunca(myargb = 3)
$ pylint a.py --reports=n
No config file found, using default configuration
************* Module a
C: 1, 0: No space allowed around keyword argument assignment
myfunca(myargb = 3)
^ (bad-whitespace)
C: 1, 0: Missing module docstring (missing-docstring)
E: 1, 0: Undefined variable 'myfunca' (undefined-variable)
$ pylint a.py --disable bad-whitespace --reports=n
No config file found, using default configuration
************* Module a
C: 1, 0: Missing module docstring (missing-docstring)
E: 1, 0: Undefined variable 'myfunca' (undefined-variable)
For completeness, you can disable the same for pep8's checker with E251
:
$ pep8 a.py
a.py:1:15: E251 unexpected spaces around keyword / parameter equals
a.py:1:17: E251 unexpected spaces around keyword / parameter equals
$ pep8 a.py --ignore=E251
AFAIK you can only disable messages down to the granularity of IDs in pylint, as all the whitespace has the same id bad-whitespace
aka C0326
you can therefore either ignore all or none.
This is the code that checks if a message is disabled, as you see it only receives the id to check against:
def is_message_enabled(self, msg_descr, line=None, confidence=None):
"""return true if the message associated to the given message id is
enabled
msgid may be either a numeric or symbolic message id.
"""
When the message is added to the lint results, you can see that bad-whitespace
is all that is passed in. The around and keyword argument assignment are simply arguments to the message.
warnings = []
if not any(good_space) and policies[0] == policies[1]:
warnings.append((policies[0], 'around'))
else:
for ok, policy, position in zip(good_space, policies, ('before', 'after')):
if not ok:
warnings.append((policy, position))
for policy, position in warnings:
construct = _name_construct(token)
count, state = _policy_string(policy)
self.add_message('bad-whitespace', line=token[2][0],
args=(count, state, position, construct,
_underline_token(token)))
The arguments to the message are displayed using the formatting string:
'C0326': ('%s space %s %s %s\n%s',
'bad-whitespace',
('Used when a wrong number of spaces is used around an operator, '
'bracket or block opener.'),
All that should help if you want to customize pylint to do what you want, and if so, a pull-request back to them would hopefully be well received.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With