Skip to content

Instantly share code, notes, and snippets.

@alamkanak
Last active April 11, 2024 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alamkanak/b61146e61887db14e390fe33427d80c1 to your computer and use it in GitHub Desktop.
Save alamkanak/b61146e61887db14e390fe33427d80c1 to your computer and use it in GitHub Desktop.
python-best-practice
  1. Install the following:
    1. VSCode
    2. Python extension
    3. Pylance extension
    4. Ruff extension
  2. Open command palette in VSCode with Cmd + Shift + P
  3. Type and select Preferences: Open Workspace Settings (JSON)
  4. Copy and paste the following settings into your workspace settings file:
    {
        "notebook.formatOnSave.enabled": true,
        "python.analysis.typeCheckingMode": "strict",
        "python.analysis.inlayHints.functionReturnTypes": true,
        "python.analysis.inlayHints.variableTypes": true,
        "python.analysis.autoImportCompletions": true,
        "[python]": {
            "editor.formatOnSave": true,
            "editor.defaultFormatter": "charliermarsh.ruff",
            "editor.codeActionsOnSave": {
                "source.fixAll": "always",
                "source.organizeImports": "always"
            }
        }
    }
  5. Save the settings to apply them. This will save a file in the file .vscode/settings.json.
  6. Make sure .vscode/settings.json file is tracked in git by running git add .vscode/settings.json.

Now, your VSCode is all set up for an optimized Python development experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment