Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsApr 30, 2026·3 min de lectura

Pylint — Comprehensive Static Code Analyzer for Python

Pylint is a static analysis tool that checks Python code for errors, enforces coding standards, detects code smells, and provides refactoring suggestions with a configurable scoring system.

Introduction

Pylint is one of the oldest and most thorough Python static analysis tools. It checks for coding errors, enforces PEP 8 style conventions, detects code smells, and scores your code on a 0-10 scale. Its extensive checker system covers everything from unused imports to complex cyclomatic complexity.

What Pylint Does

  • Detects actual errors like undefined variables, wrong argument counts, and import failures
  • Enforces coding standards based on PEP 8 with configurable rules
  • Identifies code smells such as duplicate code, too many branches, and long functions
  • Provides a numerical code quality score that tracks improvement over time
  • Generates reports with statistics on module complexity, dependencies, and raw metrics

Architecture Overview

Pylint parses Python source into an AST using the astroid library, which provides enhanced type inference beyond the standard ast module. Each checker is a visitor that walks the AST and emits messages when it detects violations. Checkers are organized into categories: convention, refactor, warning, error, and fatal. The message system supports fine-grained enable/disable controls at the file, block, or line level.

Self-Hosting & Configuration

  • Install with pip install pylint and run against any Python project
  • Generate a starter config with pylint --generate-rcfile > .pylintrc
  • Configure via .pylintrc, pyproject.toml under [tool.pylint], or setup.cfg
  • Disable specific checks with --disable=C0114,R0903 or inline # pylint: disable= comments
  • Set --jobs=0 to use all CPU cores for parallel analysis of multiple modules

Key Features

  • Over 200 built-in checks covering errors, style, refactoring, and design issues
  • The astroid engine provides deep type inference for accurate cross-module analysis
  • Plugin system allows writing custom checkers for project-specific rules
  • Editor integrations provide real-time feedback in VS Code, PyCharm, and Vim
  • Score tracking helps teams measure code quality improvements over time

Comparison with Similar Tools

  • Ruff — much faster (Rust-based) but covers fewer checker categories
  • Flake8 — lighter and faster but less thorough on type inference and design checks
  • mypy — type checker only, does not check style or code smells
  • Pyright — focused on type checking with faster performance, not a general linter
  • Bandit — security-focused scanner, not a general code quality tool

FAQ

Q: Is Pylint too slow for large projects? A: Pylint is slower than Ruff or Flake8 because it performs deeper analysis. Use --jobs=0 for parallel execution and --load-plugins selectively to improve speed. Many teams run Ruff for fast feedback and Pylint in CI for thorough checks.

Q: How do I use Pylint with pre-commit? A: Add the pylint mirror to your .pre-commit-config.yaml. For projects with dependencies, use local hooks that run in the project virtualenv to ensure accurate import checking.

Q: Can Pylint check type annotations? A: Pylint performs some type-related checks but is not a full type checker. Pair it with mypy or Pyright for comprehensive type analysis.

Q: What does the Pylint score mean? A: Pylint scores code from 0 to 10 based on the ratio of detected issues to lines of code. A score of 10 means no issues were found. The score formula is configurable.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados