Skip to main content
This guide shows a quick, practical workflow to find and resolve common Python linting errors using pylint and flake8. Follow the steps below to set up linting, interpret typical messages, and apply fixes that improve code quality and PEP 8 compliance.
A presentation slide titled "Lint Error Resolution" with a large dark-blue curved shape on the right containing the word "Demo" in bright blue. The bottom-left shows "© Copyright KodeKloud."

Prerequisites

Install the common Python linters:
You should see installation output similar to:

Create a baseline .pylintrc

Add a .pylintrc to your repository to enforce consistent rules across local development and CI. Example configuration:
This configuration disables missing-docstring checks at the top level (so you can add them gradually) and enforces formatting preferences close to PEP 8.

Run pylint

Run pylint against a module:
Typical pylint output lists issues (trailing whitespace, missing docstrings, line-too-long, import order, etc.). Example excerpt:

Common issues and how to address them

The table below maps frequent pylint/flake8 messages to causes and quick fixes.

Example: cleaned route and query snippet

Here is an excerpt of a Flask route with an SQL query (trailing whitespace removed and formatted):

Fixing specific issues — before & after examples

  1. Final newline missing
  • Add an empty line at the end of the file and re-run pylint.
  1. Missing function docstring
  • Before:
  • After:
  1. Unspecified encoding when using open()
  • Before:
  • After:
  1. Redefining builtin id
  • Before:
  • After:
  1. Import order and unused imports
  • Fix by grouping and removing unused imports:

Re-run pylint and track improvements

After applying fixes, re-run pylint. You should see many messages disappear and your score improve. Example:

Using editor or assistant helpers

Many editor-integrated assistants or IDE linters can parse pylint output and offer quick fixes (trim whitespace, add final newline, add simple docstrings, rename variables). Use these tools to speed up the cleanup, but always verify the changes.
Keep a .pylintrc (or similar) in your repository so CI, local dev, and any code generators (Cursor AI rules) produce consistent, PEP 8–aligned code. Run linters locally and in CI to catch regressions early.
When using automated assistants, confirm the file path before applying changes. Some tools may duplicate files (e.g., create both app.py and kodekloudtaskmanager.py) or apply edits to the wrong target—delete duplicates and reapply fixes if necessary.
  • Install flake8 and pylint and add a .pylintrc for consistent rules.
  • Run pylint app.py, inspect messages, and apply fixes for:
    • trailing whitespace
    • missing final newline
    • missing docstrings
    • encoding on file open
    • import order and unused imports
    • builtin name shadowing
  • Use editor/assistant helpers to speed fixes but verify file paths and changes to avoid duplicates.
  • Store lint configuration in your repo and run linters in CI to prevent regressions.

Watch Video