pylint woes

Stephen Hansen me+python at ixokai.io
Sat May 7 15:21:19 EDT 2016


Pylint is very opinionated. Feel free to adjust its configuration to
suit your opinions of style.

In particular, several of these might be related to PEP8 style issues.

On Sat, May 7, 2016, at 09:51 AM, DFS wrote:
>                                            DFS comments
> +-------------------------+------------+ -------------------------------
> |message id               |occurrences |
> +=========================+============+
> |mixed-indentation        |186         | I always use tab

And yet, it appears there's some space indentation in there. In
Notepad++ enable View->Show Symbol->Show White Space and Tab and Show
Indent Guide.

> +-------------------------+------------+
> |invalid-name             |82          | every single variable name?!

It probably defaults to PEP8 names, which are variables_like_this, not
variablesLikeThis.

> +-------------------------+------------+
> |bad-whitespace           |65          | mostly because I line up =
>                                           signs:
>                                           var1  = value
>                                           var10 = value

Yeah and PEP8 says don't do that. Adjust the configuration of pylint if
you want.

> +-------------------------+------------+
> |multiple-statements      |23          | do this to save lines.
>                                           Will continue doing it.

This you really shouldn't do, imho. Saving lines is not a virtue,
readability is -- dense code is by definition less readable.

> +-------------------------+------------+
> |no-member                |5           |
> 
> "Module 'pyodbc' has no 'connect' member"   Yes it does.
> "Module 'pyodbc' has no 'Error' member"     Yes it does.
> 
> Issue with pylint, or pyodbc?

Pylint. 

> +-------------------------+------------+
> |line-too-long            |5           | meh

I'm largely meh on this too. But again its a PEP8 thing.

> +-------------------------+------------+
> |wrong-import-order       |4           | does it matter?

Its useful to have a standard so you can glance and tell what's what and
from where, but what that standard is, is debatable.

> +-------------------------+------------+
> |missing-docstring        |4           | what's the difference between
>                                           a docstring and a # comment?

A docstring is a docstring, a comment is a comment. Google python
docstrings :) Python prefers files to have a docstring on top, and
functions beneath their definition. Comments should be used as little as
possible, as they must be maintained: an incorrect comment is worse then
no comment.

Go for clear code that doesn't *need* commenting.

> +-------------------------+------------+
> |superfluous-parens       |3           | I like to surround 'or'
>                                           statments with parens

Why?

> +-------------------------+------------+
> |multiple-imports         |2           | doesn't everyone?

I don't actually know what its complaining at.

> +-------------------------+------------+
> |bad-builtin              |2           | warning because I used filter?

Don't know what its complaining at about here either.

> +-------------------------+------------+
> |missing-final-newline    |1           | I'm using Notepad++, with
>                                           EOL Conversion set to
>                                           'Windows Format'.  How
>                                           or should I fix this?

Doesn't have anything to do with it. Just scroll to the bottom and press
enter. It wants to end on a newline, not code.

> Global evaluation
> -----------------
> Your code has been rated at -7.64/10
> 
> I assume -7.64 is really bad?
> 
> Has anyone ever in history gotten 10/10 from pylint for a non-trivial 
> program?

No clue, I don't use pylint at all.

> [1]
> pylint says "Consider using enumerate instead of iterating with range 
> and len"
> 
> the offending code is:
> for j in range(len(list1)):
>    do something with list1[j], list2[j], list3[j], etc.
> 
> enumeration would be:
> for j,item in enumerate(list1):
>    do something with list1[j], list2[j], list3[j], etc.
> 
> Is there an advantage to using enumerate() here?

Its cleaner, easier to read. In Python 2 where range() returns a list,
its faster. (In python2, xrange returns a lazy evaluating range)

Use the tools Python gives you. Why reinvent enumerate when its built
in?

-- 
Stephen Hansen
  m e @ i x o k a i . i o



More information about the Python-list mailing list