Skip to content

Feature request: When setting python.analysis.typeshedPaths, use its stubs for typing absolute imports #5209

Closed
@Avasam

Description

@Avasam

For example, in typeshed repository, I have the following configured:

    "python.analysis.typeshedPaths": [
        "${workspaceFolder}"
    ],

I'd expect absolute imports to find symbols from typeshed's own stubs, and "Go to type definition" to lead to typeshed's own .pyi (when it exists) instead of the installed library.

Here's a couple example:
image
image
When new modules get added (or a new stub gets worked on, which is full of new modules):
image

Here's the full config:

/*
 * Copy this file as `.vscode/settings.json` to configure VSCode for this workspace.
 * Unfortunately, VSCode doesn't (yet) offer any way to have "workspace defaults" or "user-worspace settings",
 * so offering defaults to copy is the best we can do at the moment.
 *
 * ⚠ Disclaimer: The typeshed team doesn't commit to maintaining this file. It exists purely for your ease of use.
*/
{
    // Don't format on save for formatters we don't explicitely control
    "editor.formatOnSave": false,
    "editor.codeActionsOnSave": {
        "source.fixAll": false
    },
    // Set file associations to support comments syntax highlight
    "files.associations": {
        "settings.default.json": "jsonc",
        "pyrightconfig*.json": "jsonc",
        ".flake8": "properties",
        "stubtest_allowlist*.txt": "properties",
        "**/stubtest_allowlists/*.txt": "properties",
        "pytype_exclude_list.txt": "properties"
    },
    "files.exclude": {
        "**/.*_cache": true, // mypy and Ruff cache
        "**/__pycache__": true
    },
    "files.eol": "\n",
    "files.insertFinalNewline": true,
    "files.trimFinalNewlines": true,
    "files.trimTrailingWhitespace": true,
    "editor.comments.insertSpace": true,
    "editor.insertSpaces": true,
    "editor.detectIndentation": false,
    "editor.tabSize": 2,
    "[json][jsonc][python][toml]": {
        "editor.tabSize": 4
    },
    "editor.rulers": [
        90,
        130
    ],
    "[git-commit]": {
        "editor.rulers": [
            72
        ]
    },
    // Format on save for formatters we explicitely control
    "[json][jsonc][yaml][python][toml]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.fixAll": true,
            // Allow isort or Ruff to organize imports
            "source.organizeImports": true
        }
    },
    "[json][jsonc]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "[yaml]": {
        "editor.defaultFormatter": "redhat.vscode-yaml"
    },
    "[toml]": {
        "editor.rulers": [
            90
        ],
        "editor.defaultFormatter": "tamasfe.even-better-toml"
    },
    "[python]": {
        "editor.rulers": [
            130
        ],
        "editor.defaultFormatter": "ms-python.black-formatter"
    },
    // python.analysis is Pylance (pyright) configurations
    "python.analysis.fixAll": [
        "source.unusedImports"
        // Explicitly omiting "source.convertImportFormat", some stubs use relative imports
    ],
    "python.analysis.typeshedPaths": [
        "${workspaceFolder}"
    ],
    "python.analysis.extraPaths": [
        "tests"
    ],
    "mypy-type-checker.importStrategy": "fromEnvironment",
    "mypy-type-checker.args": [
        "--custom-typeshed-dir=${workspaceFolder}",
        "--python-version=3.8",
        "--strict",
        // Needed because a library stubbed in typeshed won't necessarily be installed in the dev's environment
        "--ignore-missing-imports"
    ],
    // Ensure typeshed's configs are used, and not user's VSCode settings
    "flake8.args": [
        "--config=.flake8"
    ],
    "flake8.importStrategy": "fromEnvironment",
    "black-formatter.importStrategy": "fromEnvironment",
    // Using Ruff instead of isort
    "isort.check": false,
    "ruff.importStrategy": "fromEnvironment",
    "ruff.fixAll": true,
    "ruff.organizeImports": true,
    "evenBetterToml.formatter.alignComments": false,
    "evenBetterToml.formatter.alignEntries": false,
    "evenBetterToml.formatter.allowedBlankLines": 1,
    "evenBetterToml.formatter.arrayAutoCollapse": true,
    "evenBetterToml.formatter.arrayAutoExpand": true,
    "evenBetterToml.formatter.arrayTrailingComma": true,
    "evenBetterToml.formatter.columnWidth": 90,
    "evenBetterToml.formatter.compactArrays": true,
    "evenBetterToml.formatter.compactEntries": false,
    "evenBetterToml.formatter.compactInlineTables": false,
    "evenBetterToml.formatter.indentEntries": false,
    "evenBetterToml.formatter.indentTables": false,
    "evenBetterToml.formatter.inlineTableExpand": false,
    "evenBetterToml.formatter.reorderArrays": true,
    "evenBetterToml.formatter.trailingNewline": true,
    // We like keeping TOML keys in a certain non-alphabetical order that feels more natural
    "evenBetterToml.formatter.reorderKeys": false
}

Metadata

Metadata

Assignees

Labels

user respondedWas "waiting for user response" and they responded

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions