Skip to content

Latest commit

 

History

History
64 lines (43 loc) · 2.88 KB

File metadata and controls

64 lines (43 loc) · 2.88 KB

Overview

reportMissingTypeStubs is a diagnostic in Pylance and Pyright that warns when a module is missing type stubs (.pyi files) or type annotations. This helps catch missing type information for third-party libraries, improving static analysis and type safety.

Representative Issues

  • #9393: Ensure that all modules within the 'google.cloud' namespace include a 'py.typed' marker and appropriate type annotations to avoid errors like 'reportMissingTypeStubs'.

Examples

import some_library  # Warning: Stub file not found for "some_library"

Fix — install type stubs if available:

pip install types-some_library
# or for common packages:
pip install types-requests types-PyYAML

Fix — use useLibraryCodeForTypes to infer types from source:

// .vscode/settings.json
{
    "python.analysis.useLibraryCodeForTypes": true
}

Common Fixes & Workarounds

  1. Install or generate type stubs (.pyi files) for third-party libraries.
  2. Use libraries that provide type annotations or a py.typed marker file.
  3. Contribute type stubs to the typeshed repository or the library itself if missing.
  4. Review the Pyright configuration documentation for options to adjust or suppress this diagnostic if needed.

Stub-package version mismatches

Stub-only packages (like boto3-stubs, types-requests) must match the version of the library they describe. If you install types-requests==2.28.0 but have requests==2.31.0, the stubs may define different APIs, causing false errors.

Fix: keep stub-package versions aligned with library versions:

pip install requests==2.31.0 types-requests==2.31.0

For AWS SDK stubs (boto3-stubs, mypy-boto3-*), install matching versions and the service-specific sub-packages:

pip install 'boto3-stubs[s3,ec2]'  # installs service stubs for s3 and ec2

Diagnosis: run pip list | grep types- (or pip list | grep stubs) and compare versions against the library they describe.

If a stub package produces errors itself (e.g., internal stub inconsistencies), check for newer versions or file an issue on the stub package's repository.

See Also