
Prerequisites
Install the common Python linters:Create a baseline .pylintrc
Add a .pylintrc to your repository to enforce consistent rules across local development and CI. Example configuration:
Run pylint
Run pylint against a module: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
- Final newline missing
- Add an empty line at the end of the file and re-run pylint.
- Missing function docstring
- Before:
- After:
- Unspecified encoding when using open()
- Before:
- After:
- Redefining builtin
id
- Before:
- After:
- 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.Summary & recommended workflow
- Install flake8 and pylint and add a
.pylintrcfor 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.