Pylint has a configuration option which is suppose to let you do things like this:
for dummy_var in range(10):
print 'hello world'
Ordinarily, having an unused variable like dummy_var would give you a warning, but since the beginning matches the regular expression in dummy-variables-rgx, no warning is given. By default the value is _|dummy, so the following should generate no warnings:
for _ in range(10):
print 'hello world'
The problem is that it does. It gives the warning about an invalid name "_".
How can I fix this?
If I had read the error message more carefully, I would have realized that I was no longer getting an unused variable warning, but a warning about a bad variable name. In other words, something like this would be fine:
for _unused in range(10):
print 'hello world'
This is okay since it matches the regular expression in variable-rgx. However, the original form
for _ in range(10):
print 'hello world'
does not work since _ does not match the value of variable-rgx. In order to have no warnings for this unused and invalid variable name, the name needs to be added to the list of white-listed names in good-names. Once this is done, no more warnings will be generated.
I added this to my .pylintrc:
dummy-variables-rgx=^_.*
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