Questions tagged [pylint]

Pylint is a Python source code analyzer looking for bugs and signs of poor quality.

Pylint is a Python tool that checks if a module satisfies a coding standard.

1691 questions
77
votes
7 answers

Finding dead code in large python project

I've seen How can you find unused functions in Python code? but that's really old, and doesn't really answer my question. I have a large python project with multiple libraries that are shared by multiple entry point scripts. This project has been…
Brian Postow
  • 11,709
  • 17
  • 81
  • 125
76
votes
4 answers

Why doesn't Pylint like built-in functions?

I have a line like this: filter(lambda x: x == 1, [1, 1, 2]) Pylint is showing a warning: W: 3: Used builtin function 'filter' Why is that? is a list comprehension the recommended method? Of course I can rewrite this like this: [x for x in [1, 1,…
igorgue
  • 17,884
  • 13
  • 37
  • 54
74
votes
1 answer

How to handle the pylint message: Warning: Method could be a function

I have a python class and ran pylint against it. One message it gave was: Warning: Method could be a function Is this telling me that it would be better to move this method out of the class because it doesn't use any instance variables? In C# I…
bignum
  • 3,448
  • 3
  • 21
  • 18
73
votes
4 answers

Best practice for setting the default value of a parameter that's supposed to be a list in Python?

I have a Python function that takes a list as a parameter. If I set the parameter's default value to an empty list like this: def func(items=[]): print items Pylint would tell me "Dangerous default value [] as argument". So I was wondering what…
Jack Z
  • 2,572
  • 4
  • 20
  • 17
69
votes
6 answers

Should wildcard import be avoided?

I'm using PyQt and am running into this issue. If my import statements are: from PyQt4.QtCore import * from PyQt4.QtGui import * then pylint gives hundreds of "Unused import" warnings. I'm hesitant to just turn them off, because there might be…
Colin
  • 10,447
  • 11
  • 46
  • 54
66
votes
9 answers

Ignore by directory using Pylint

The following is from the Pylint documentation: --ignore= Add to the black list. It should be a base name, not a path. You may set this option multiple times. [current: %default] Yet, I'm not having luck…
Ciantic
  • 6,064
  • 4
  • 54
  • 49
65
votes
14 answers

Pylint can't find SQLAlchemy query member

I have a Flask (v0.10.1) application using Flask-SQLAlchemy (v2.0) and I'm trying to configure Pylint to check it. Running with Python 3.4.2. First error was: Instance of 'SQLAlchemy' has no 'Table' member (no-member) And I fixed this one ignoring…
Pedro Teixeira
  • 659
  • 1
  • 5
  • 7
63
votes
4 answers

Pylint: overriding max-line-length in individual file

Is it possible to change max-line-length settings for one file out of a project (while performing all other checks defined in rc file on it)? Ideally, it should behave like inline pylint: disable=x comments. I've tried putting this line at the…
Łukasz Rogalski
  • 22,092
  • 8
  • 59
  • 93
60
votes
3 answers

Pylint showing invalid variable name in output

I made a simple python script to post data on a website. #Imports url_to_short = sys.argv[1] post_url = 'https://www.googleapis.com/urlshortener/v1/url' headers = {'Content-Type': 'application/json'} data = {'longUrl': url_to_short} post_data =…
RanRag
  • 48,359
  • 38
  • 114
  • 167
57
votes
4 answers

"No name in module" error from Pylint

I have a file named main.py with the following code: #!/usr/bin/env python3 import utils.stuff if __name__ == "__main__": print("hi from main.py") utils.stuff.foo() In the directory with main.py, I have a subdirectory named utils which…
Elias Zamaria
  • 96,623
  • 33
  • 114
  • 148
56
votes
4 answers

pylint 1.4 reports E1101(no-member) on all C extensions

We've been long-time fans of pylint. Its static analysis has become a critical part of all our python projects and has saved tons of time chasing obscure bugs. But after upgrading from 1.3 -> 1.4, almost all compiled c extensions result in…
user590028
  • 11,364
  • 3
  • 40
  • 57
53
votes
2 answers

Python - Should I put my helper functions inside or outside the class?

In Python, if some methods of a class need a helper function, but the helper function itself doesn't use anything in the class, should I put the helper function inside or outside the class? I tried putting it inside but PyLint was complaining that…
Jack Z
  • 2,572
  • 4
  • 20
  • 17
49
votes
3 answers

How do I automatically fix lint issues reported by pylint?

Just like we have "eslint --fix" to automatically fix lint problems in Javascript code, do we have something for pylint too for Python code?
ThinkGeek
  • 4,749
  • 13
  • 44
  • 91
49
votes
2 answers

Pylint to show only warnings and errors

I would like to use pylint to check my code but I am only interested in error and warning levels. Is there a way to do that in command line or in pylintrc? I am not interested in filtering given issues (like listing all messages in MESSAGE CONTROL),…
joetde
  • 1,556
  • 1
  • 16
  • 26
49
votes
1 answer

pylint duplicate code false positive

I have this code in (many) of my Python files for a project. from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals from pprint import pformat Pylint…
Sardathrion - against SE abuse
  • 17,269
  • 27
  • 101
  • 156