Questions tagged [pylint]

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

pylint
Filter by
Sorted by
Tagged with
433 votes
14 answers
578k views

How do I disable a Pylint warning?

I'm trying to disable warning C0321 ("more than one statement on a single line" -- I often put if statements with short single-line results on the same line), in Pylint 0.21.1 (if it matters:...
Head Geek's user avatar
  • 39.1k
409 votes
2 answers
147k views

Pylint, PyChecker or PyFlakes? [closed]

I would like to get some feedback on these tools on: features; adaptability; ease of use and learning curve.
Bite code's user avatar
  • 587k
342 votes
9 answers
192k views

PyLint message: logging-format-interpolation

For the following code: logger.debug('message: {}'.format('test')) pylint produces the following warning: logging-format-interpolation (W1202): Use % formatting in logging functions and pass ...
pfnuesel's user avatar
  • 14.7k
330 votes
35 answers
469k views

PyLint "Unable to import" error - how to set PYTHONPATH?

I'm running PyLint from inside Wing IDE on Windows. I have a sub-directory (package) in my project and inside the package I import a module from the top level, ie. __init__.py myapp.py one.py subdir\ ...
EMP's user avatar
  • 60.5k
319 votes
5 answers
296k views

Is it possible to ignore one single specific line with Pylint?

I have the following line in my header: import config.logging_settings This actually changes my Python logging settings, but Pylint thinks it is an unused import. I do not want to remove unused-...
The Unfun Cat's user avatar
256 votes
2 answers
134k views

Why is the empty dictionary a dangerous default value in Python? [duplicate]

I put a dict as the default value for an optional argument to a Python function, and pylint (using Sublime package) told me it was dangerous. Can someone explain why this is the case? And is a better ...
tscizzle's user avatar
  • 11.7k
247 votes
40 answers
444k views

Pylint "unresolved import" error in Visual Studio Code

I am using the following setup macOS v10.14 (Mojave) Python 3.7.1 Visual Studio Code 1.30 Pylint 2.2.2 Django 2.1.4 I want to use linting to make my life a bit easier in Visual Studio Code. However, ...
jAC's user avatar
  • 3,255
238 votes
4 answers
100k views

Why is the use of len(SEQUENCE) in condition values considered incorrect by Pylint?

Considering this code snippet: from os import walk files = [] for (dirpath, _, filenames) in walk(mydir): # More code that modifies files if len(files) == 0: # <-- C1801 return None I was ...
E_net4's user avatar
  • 28.9k
229 votes
7 answers
159k views

Instance attribute attribute_name defined outside __init__

I split up my class constructor by letting it call multiple functions, like this: class Wizard: def __init__(self, argv): self.parse_arguments(argv) self.wave_wand() # declaration ...
Steven Liao's user avatar
  • 3,697
205 votes
3 answers
181k views

How do I create a pylintrc file

I am running linux. Can I do something like pylint --generate-rcfile > .pylintrc and then make changes to the resulting .pylintrc file to override the default settings? And if so should it be in my ...
user3330833's user avatar
  • 2,269
200 votes
18 answers
352k views

How do I disable "missing docstring" warnings at a file-level in Pylint?

Pylint throws errors that some of the files are missing docstrings. I try and add docstrings to each class, method and function, but it seems that Pylint also checks that files should have a docstring ...
Mridang Agarwalla's user avatar
193 votes
23 answers
108k views

How do I get Pylint to recognize NumPy members?

I am running Pylint on a Python project. Pylint makes many complaints about being unable to find NumPy members. How can I avoid this while avoiding skipping membership checks? From the code: import ...
Alphadelta14's user avatar
  • 2,864
169 votes
4 answers
121k views

What does Pylint's "Too few public methods" message mean?

I'm running Pylint on some code, and receiving the error "Too few public methods (0/2)". What does this message mean? The Pylint documentation is not helpful: Used when a class has too few ...
monsur's user avatar
  • 46.6k
151 votes
13 answers
64k views

Using Pylint with Django

I would very much like to integrate pylint into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:E1101: *%s %r has ...
rcreswick's user avatar
  • 16.6k
149 votes
7 answers
74k views

Why does Pylint object to single-character variable names?

I'm still getting used to Python conventions and using Pylint to make my code more Pythonic, but I'm puzzled by the fact that Pylint doesn't like single character variable names. I have a few loops ...
Amanda's user avatar
  • 12.4k
145 votes
6 answers
137k views

Disable all Pylint warnings for a file

We are using Pylint within our build system. We have a Python package within our code base that has throwaway code, and I'd like to disable all warnings for a module temporarily so I can stop bugging ...
mvanveen's user avatar
  • 9,922
131 votes
8 answers
217k views

ImportError : Attempted relative import with no known parent package [duplicate]

I am learning to program with python and I am having issues with importing from a module in a package. I am usingvisual studio code with Python 3.8.2 64 bit. My Project Directory .vscode ├── ecommerce ...
Isaac Anatolio's user avatar
125 votes
17 answers
151k views

Run Pylint for all Python files in a directory and all subdirectories

I have find . -iname "*.py" -exec pylint -E {} ;\ and FILES=$(find . -iname "*.py") pylint -E $FILES If I understand correctly, the first command will run pylint for each of the Python files, the ...
Alan Evangelista's user avatar
109 votes
8 answers
130k views

How to run Pylint with PyCharm

I want to configure Pylint as an external tool in my entire project directory for a Python project that I'm working on. I've tried to use the repository as a module with __init__.py and without, and ...
Wasif Hyder's user avatar
  • 1,319
108 votes
1 answer
65k views

How to fix pylint logging-not-lazy? [duplicate]

I am using prospector to examine my code. Pylint returned a logging-not-lazy warning about my debug message. Line: 31 pylint: logging-not-lazy / Specify string format arguments as logging function ...
Valeriy Solovyov's user avatar
102 votes
8 answers
134k views

Avoid Pylint warning E1101: 'Instance of .. has no .. member' for class with dynamic attributes

Imagine a function which dynamically adds attributes to an object using setattr. The reason for doing so is that I want to map some external structure (e.g. a given parameter tree) to an object: ...
frans's user avatar
  • 9,342
102 votes
1 answer
67k views

Pylint raise-missing-from

I have a pylint message (w0707) on this piece of code (from https://www.django-rest-framework.org/tutorial/3-class-based-views/): class SnippetDetail(APIView): """ Retrieve, ...
Andre Rivoallan's user avatar
99 votes
4 answers
34k views

pytest fixtures Redefining name from outer scope [pylint]

I'm learning pytest and I lint my code with pylint. But pylint still complaints about: W0621: Redefining name %r from outer scope (line %s) for the following example from pytest: # test_wallet.py @...
oglop's user avatar
  • 1,265
96 votes
15 answers
197k views

Error message "Linter pylint is not installed"

I want to run Python code in Microsoft Visual Studio Code but it gives an error: Linter pylint is not installed I installed: The Visual Studio Code Python extension Python 3 Anaconda How can I ...
Naveed Aheer's user avatar
  • 1,765
89 votes
6 answers
49k views

How do I tell PyLint "it's a variable, not a constant" to stop message C0103?

I have a module-level variable in my Python 2.6 program named "_log", which PyLint complains about: C0103: Invalid name "_log" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$) Having read this answer I ...
EMP's user avatar
  • 60.5k
85 votes
9 answers
71k views

PyLint not recognizing cv2 members

I am running pylint on an opencv project and I am getting many pylint errors in VS code about members not being present. Example code: import cv2 cv2.imshow(....) Errors obtained: However , the ...
Kitwradr's user avatar
  • 2,068
84 votes
4 answers
77k views

How to deal with Pylint's "too-many-instance-attributes" message?

I have just tried to lint some code with Pylint, and the last remaining error is R0902: too-many-instance-attributes (8/7) I understand the rationale behind limiting the number of instance ...
diwhyyyyy's user avatar
  • 6,262
81 votes
11 answers
170k views

Python: avoiding Pylint warnings about too many arguments

I want to refactor a big Python function into smaller ones. For example, consider this following code snippet: x = x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 Of course, this is a trivial example. In ...
Anonymous's user avatar
  • 3,021
80 votes
3 answers
98k views

Pylint invalid constant name

I'm receiving a Pylint error regarding my constant: MIN_SOIL_PARTICLE_DENS (invalid name). Any ideas why this constant is wrong? Here's my full function: def bulk_density(clay, sand, organic_matter): ...
gcamargo's user avatar
  • 3,833
78 votes
7 answers
27k views

Finding dead code in large python project [closed]

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 ...
Brian Postow's user avatar
77 votes
4 answers
29k views

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 ...
igorgue's user avatar
  • 18.1k
74 votes
4 answers
30k views

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 ...
Jack Z's user avatar
  • 2,622
74 votes
1 answer
52k views

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 ...
bignum's user avatar
  • 3,448
70 votes
6 answers
63k views

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 ...
Colin's user avatar
  • 10.6k
68 votes
9 answers
83k views

Ignore by directory using Pylint

The following is from the Pylint documentation: --ignore=<file> Add <file or directory> to the black list. It should be a base name, not a path. You may set this option multiple ...
Ciantic's user avatar
  • 6,194
64 votes
14 answers
48k views

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'...
Pedro Teixeira's user avatar
64 votes
4 answers
96k views

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 ...
Łukasz Rogalski's user avatar
60 votes
3 answers
106k views

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'...
RanRag's user avatar
  • 49k
58 votes
4 answers
19k views

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, ...
user590028's user avatar
  • 11.6k
58 votes
4 answers
110k views

"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 ...
Elias Zamaria's user avatar
54 votes
2 answers
30k views

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

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 ...
Jack Z's user avatar
  • 2,622
54 votes
3 answers
60k views

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's user avatar
  • 4,897
53 votes
2 answers
42k views

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 ...
joetde's user avatar
  • 1,606
50 votes
1 answer
41k views

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 ...
Sardathrion - against SE abuse's user avatar
49 votes
13 answers
64k views

Why does it say that module pygame has no init member?

This is the code I have: import pygame pygame.init() I'm very confused because if I try to run the file, then there seems to be no issue, but pylint says the following: E1101:Module 'pygame' has ...
Ludde's user avatar
  • 491
47 votes
5 answers
60k views

Error message "python-pylint 'C0103:Invalid constant name"

I'm confused about the error(s) in this photo: I don't know how to fix them. My program is a Python-Flask web frame. When I use Visual Studio Code to debug my program, Pylint shows these errors. I ...
Xing's user avatar
  • 167
46 votes
6 answers
73k views

Silence PyLint warning about unused variables for string interpolation

The say module brings string interpolation to Python, like this: import say def f(a): return say.fmt("The value of 'a' is {a}") However, PyLint complains that the variable 'a' is never used. ...
Eleno's user avatar
  • 2,924
45 votes
10 answers
18k views

Invoking Pylint programmatically

I'd like to invoke the Pylint checker, limited to the error signalling part, as part of my unit testing. So I checked the Pylint executable script, got to the pylint.lint.Run helper class and there I ...
mariotomo's user avatar
  • 9,548
45 votes
2 answers
10k views

Pylint: Disable specific warnings for specific folder

We have a Python project laid out like this: project/ ├── .pylintrc ├── module1.py ├── module2.py └── tests/ ├── test_module1.py └── test_module2.py Our unit and function tests reside in the ...
imolit's user avatar
  • 8,152
44 votes
4 answers
10k views

List of pylint human readable message ids?

Recent versions of pylint allow for suppressing messages with human readable message ids. For example, instead of class MyTest(unittest.TestCase): # pylint: disable=R0904 ... you can specify: ...
Frank Niessink's user avatar

1
2 3 4 5
35