dev-blog

Great! Here’s a fully integrated, ready-to-use setup for a Python project using Pylance with strict type checking. It includes both .vscode/settings.json and pyrightconfig.json so your project is consistent in VS Code and in CI/other editors.


.vscode/settings.json

{
  // Python interpreter to use
  "python.pythonPath": ".venv/bin/python3.12",

  // Enable Pylance as the language server
  "python.languageServer": "Pylance",

  // Exclude folders like virtual environments or build artifacts
  "files.exclude": {
    "**/__pycache__": true,
    "**/.venv": true,
    "**/.pytest_cache": true
  }
}

pyrightconfig.json

{
  // Strict type checking
  "typeCheckingMode": "strict",

  // Folders to exclude from type checking
  "exclude": ["**/tests", "**/.venv", "**/__pycache__"],

  // Report issues for optional member access
  "reportOptionalMemberAccess": true,

  // Report missing imports
  "reportMissingImports": true,

  // Ignore private usage warnings
  "reportPrivateUsage": false
}

How it works

  1. VS Code .vscode/settings.json:

    • Configures Pylance in the editor.
    • Enables strict type checking while controlling warning vs error levels.
  2. pyrightconfig.json:

    • Ensures the same type checking rules are enforced outside VS Code (CI pipelines, command line, other editors using Pyright).
  3. Consistency:

    • Both files ensure your project always uses the same type checking rules.
    • Excludes virtual environments, cache folders, and test folders from unnecessary checks.

If you want, I can also add some extra recommended Pylance/VS Code settings like auto-imports, stub paths, and strict function return checks for an even more robust setup. It’s often what professional Python teams use.

Do you want me to add those too?