Pylint configuration problems

74 views Asked by At

I am trying to configure pylint to accept two letter variable names without giving the 'doesn't conform to snake_case naming style' warning.

I've set up the default ~/pylintrc and have tried editing it as follows

  • adding variable-rgx=[a-z_][a-z0-9_]{1-30}$
  • adding variable-rgx=[a-z\_][a-z0-9_]{1-30}$ (I have no idea why the backslash is there, but I found it on a random website talking about configuring pylint and thought it worth a shot)
  • both of the above with and without commenting out variable-naming-style=snake_case
  • adding a few of the common 2 letter variables I use to good-names

This is happening (perhaps unsurprisingly) when I run pylint direct in my terminal or via Vim/Ale. I have closed down and restarted my terminal several times and even rebooted once to try and clear any caching that may be going on and I cannot get this to work.

Strangely, changing max-line-length to 120 works just fine, so I know pylint is actually reading ~/pylintrc. Why does this work and my efforts above have not?

1

There are 1 answers

0
Friedrich On

Let's go through your approaches and sub-questions one by one:

adding variable-rgx=[a-z_][a-z0-9_]{1-30}$

There's a typo in the repetition specifier. It needs to be a comma instead of a hyphen. The line below will work as expected:

variable-rgx=[a-z_][a-z0-9_]{1,30}$
    this character changed ---^

And that's already the solution. Now let's take a look at the other approaches, too.

adding variable-rgx=[a-z\_][a-z0-9_]{1-30}$ (I have no idea why the backslash is there, but I found it on a random website talking about configuring pylint and thought it worth a shot)

This suffers from the typo as above. I have no idea what the backslash is supposed to do, either. It allows variables like \foo - which are still invalid syntax in Python - yay, I guess?

Remember kids, don't put random stuff from random websites into your config.

both of the above with and without commenting out variable-naming-style=snake_case

This is inconsequential as variable-rgx overrides variable-naming-style.

adding a few of the common 2 letter variables I use to good-names

This does work in the individual case. It overwrites the (sensible) defaults of ('i', 'j', 'k', 'ex', 'Run', '_') as documented, though.

Assuming you want to whitelist yo and oi, you'd add the following line to your pylintrc:

good-names=i,j,k,ex,Run,_,yo,oi

I have closed down and restarted my terminal several times and even rebooted once to try and clear any caching that may be going on and I cannot get this to work.

As far as I know, there's no caching whatsoever involved. Changes are applied instantly. This even holds true when running pylint from an IDE or Vim/ALE as in your case (which is btw what I'm also using). It either works right now or you did something wrong.

In general, I've found it very helpful to try pylint options from the command line first and put them in pylintc only when I've confirmed they work. This is made easy by the fact that any command line parameter --foo becomes foo in pylintrc.