Editor Integration
IDE integration surfaces lint errors, type issues, and formatting fixes as you type. Fast feedback loops keep code clean without waiting for CI.
Recipe
VS Code extensions:
charliermarsh.ruff(Ruff)ms-python.mypy-type-checkeror built-in Pylance (pyright)
// .vscode/settings.json
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll.ruff": "explicit",
"source.organizeImports.ruff": "explicit"
}
},
"ruff.configuration": "pyproject.toml"
}When to reach for this:
- Setting up a new developer machine
- Lint errors only appear in CI (too late)
- Team wants consistent editor behavior via committed settings
Working Example
// .vscode/settings.json (commit this file)
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"ruff.enable": true,
"ruff.lint.run": "onSave",
"mypy-type-checker.args": ["src/"],
"mypy-type-checker.severity": {
"error": "Error",
"note": "Information"
}
}// .vscode/extensions.json
{
"recommendations": [
"charliermarsh.ruff",
"ms-python.python",
"ms-python.mypy-type-checker"
]
}What this demonstrates:
- Format on save with ruff
- Import organization on save
- mypy errors shown inline
- Extension recommendations for one-click setup
Deep Dive
VS Code Setup
| Setting | Effect |
|---|---|
formatOnSave | Auto-format with ruff |
source.fixAll.ruff | Auto-fix lint violations |
source.organizeImports.ruff | Sort imports on save |
python.defaultInterpreterPath | Point to project .venv |
PyCharm Setup
- Settings > Tools > Ruff: enable, point to project
pyproject.toml - Settings > Tools > Python Integrated Tools > Default formatter: Ruff
- Enable mypy plugin: Settings > Tools > Mypy, set config path
Gotchas
- Wrong Python interpreter - lint runs against system packages. Fix: select
.venvinterpreter in VS Code status bar. - No committed
.vscode/settings.json- each dev configures differently. Fix: commit shared settings (not personal keybindings). - Pylance and mypy both enabled - duplicate errors. Fix: pick one type checker in the editor; run the other in CI if needed.
- Format on save without ruff extension - Black or autopep8 conflicts. Fix: set
defaultFormatterto ruff explicitly. - Ruff not finding pyproject.toml - runs with defaults. Fix: open the project root folder, not a subdirectory.
Alternatives
| Alternative | Use When | Don't Use When |
|---|---|---|
| CI only | No local setup time | Active development |
| Neovim + conform.nvim | Terminal-centric workflow | Team uses VS Code |
| Zed editor | Lightweight alternative | Need PyCharm Django tools |
FAQs
VS Code or PyCharm for Python?
Both work well. VS Code + ruff + Pylance is lighter. PyCharm excels for Django refactoring.
How do I select the venv in VS Code?
Command Palette > Python: Select Interpreter > choose .venv/bin/python.
Does Pylance replace mypy?
Pylance (pyright) is fast for editing. mypy in CI catches issues Pylance may miss. Use both or pick one.
How do I disable format on save for one file?
Not easily per-file. Use # fmt: off blocks for specific sections.
Can I share settings without forcing them?
Use extensions.json for recommendations; settings.json for team defaults. Personal overrides go in user settings.
How do I see ruff errors inline?
Install ruff extension. Errors appear as squiggles; hover for rule explanation.
PyCharm ruff plugin setup?
Install Ruff plugin from marketplace. Enable in Settings > Tools > Ruff.
What about devcontainers?
Add extensions to devcontainer.json customizations.vscode.extensions.
How do I fix all ruff issues at once?
Command Palette > Ruff: Fix all auto-fixable problems.
Editor shows different errors than CI?
Sync ruff version in pre-commit rev with pyproject.toml dev dependency.
Related
- Ruff Setup - ruff configuration
- pre-commit Hooks - git-level checks
- mypy & pyright in CI - type checking
- Linting & Formatting Best Practices - team standards
Stack versions: This page was written for Python 3.14.0, FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.