Pylint

4.0.5 · active · verified Sat Mar 28

Pylint is a widely used static code analyzer for Python. It inspects source code without execution to detect programming errors, enforce coding standards (like PEP 8), identify code smells, and suggest refactorings. It provides a detailed report and a code quality score. Pylint maintains an active development status with regular releases, including minor versions for new checks and bug fixes, and major versions that may introduce breaking changes to options or output formats.

Warnings

Install

Imports

Quickstart

The most common way to use Pylint is via the command line, simply by pointing it to a Python file, module, or package. For integration into tools or CI/CD pipelines, Pylint can also be invoked programmatically using `pylint.lint.Run`, allowing for custom reporters and output handling. The quickstart demonstrates both methods.

import os
import io
from pylint.lint import Run
from pylint.reporters.text import TextReporter

# Create a dummy Python file for linting
with open('my_module.py', 'w') as f:
    f.write('"""A simple module."""
MY_CONSTANT = 10
def my_function(arg1, arg2):  # arg2 is unused
    return arg1 + MY_CONSTANT
')

# --- Command Line Usage ---
print("\n--- Command Line Pylint ---")
os.system('pylint my_module.py')

# --- Programmatic Usage ---
print("\n--- Programmatic Pylint ---")
# Capture output to a string buffer
pylint_output = io.StringIO()
reporter = TextReporter(pylint_output)

# Run Pylint on the module, disabling reports for cleaner output
# do_exit=False prevents sys.exit() on linting issues
Run(['my_module.py', '--disable=C0114,C0116,R0903', '--reports=no'], reporter=reporter, do_exit=False)

print(pylint_output.getvalue())

# Clean up the dummy file
os.remove('my_module.py')

view raw JSON →