pylint woes

Michael Selik michael.selik at gmail.com
Sat May 7 14:42:33 EDT 2016


On Sat, May 7, 2016 at 12:56 PM DFS <nospam at dfs.com> wrote:

> |mixed-indentation        |186         | I always use tab
>

Don't mix tabs and spaces. I suggest selecting all lines and using your
editor to convert spaces to tabs. Usually there's a feature to "tabify".


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

Class names should be CamelCase
Everything else should be lowercase_with_underscores


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

Sure, that's your style. But pylint likes a different style. It's good to
use a standard. If it's just you, I suggest conforming to pylint. If you're
already on a team, use your team's standard.

+-------------------------+------------+
> |trailing-whitespace      |59          | heh!
>

Get rid of it. Save some bytes.


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

If you want to share your code with others, you should conform to community
standards to make things easier for others to read. Further, if you think
the core contributors are expert programmers, you should probably take
their advice: "sparse is better than dense". Do your future-self a favor
and write one statement per line. Today you find it easy to read. Six
months from now you won't.


> +-------------------------+------------+
> |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?
>

Not sure. Maybe pyodbc is written in a way that pylint can't see it's
connect or Error method/attribute.


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

Yeah, I think 80 characters can be somewhat tight. Still, 5 long lines in
200ish lines of code? Sounds like you might be doing too much in those
lines or have too many levels of indentation.
"Sparse is better than dense"
"Flat is better than nested"


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

No. I think pylint likes to alphabetize. With only 4 imports, it doesn't
matter. Still, why not alphabetize?


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

Docstrings are tools for introspection. Many things in Python access the
__doc__ attribute to help you. Comments are never seen by module users.


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

Ok. But over time you'll get used to not needing them. Edward Tufte says
you should have a high "information-to-ink" ratio.


> +-------------------------+------------+
> |redefined-outer-name     |3           | fixed. changed local var names.
> +-------------------------+------------+
> |redefined-builtin        |2           | fixed. Was using 'zip' and 'id'
> +-------------------------+------------+
> |multiple-imports         |2           | doesn't everyone?
>

Yeah, I do that as well.


> +-------------------------+------------+
> |consider-using-enumerate |2           | see below [1]
>

As Chris explained.


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

I think pylint likes comprehensions better. IMHO filter is OK. If you're
using a lambda, change to a comprehension.


> +-------------------------+------------+
> |unused-import            |1           | fixed
> +-------------------------+------------+
> |unnecessary-pass         |1           | fixed. left over from
>                                           Try..Except
> +-------------------------+------------+
> |missing-final-newline    |1           | I'm using Notepad++, with
>                                           EOL Conversion set to
>                                           'Windows Format'.  How
>                                           or should I fix this?
>

Add a few blank lines to the end of your file.


> +-------------------------+------------+
> |fixme                    |1           | a TODO statement
> +-------------------------+------------+
>
> 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?
>

I'm certain of it.



More information about the Python-list mailing list