Pyright: reportMissingTypeStubs remains despite having created a stub

Created on 18 Jul 2020  ·  5Comments  ·  Source: microsoft/pyright

prereqs

pip install botocore==1.17.23

pyrightconfig.json

{
    "include": [
        "test.py"
    ],
    "strict": [
        "test.py"
    ]
}

test.py

import botocore.exceptions

try:
    pass
except botocore.exceptions.ClientError as e:
    raise e

Pyright/Pylance in VSCode reports

Stub file not found for "botocore.exceptions" Pylance (reportMissingTypeStubs)

I run the Quick Fix Create Type Stub For "botocore.exceptions". This creates exceptions.pyi:

$ tree typings
typings
└── botocore
    └── botocore
        ├── exceptions.pyi
        └── vendored
            ├── __init__.pyi
            └── requests
                ├── __init__.pyi
                ├── exceptions.pyi
                └── packages
                    ├── __init__.pyi
                    └── urllib3
                        ├── __init__.pyi
                        └── exceptions.pyi

6 directories, 7 files

However, the reportMissingTypeStubs error does not go away.

From the CLI:

Loading configuration file at /Users/tekumara/.virtualenvs/tmp-8a56f66a9ba27e7/pyrightconfig.json
Assuming Python version 3.6
Assuming Python platform Darwin
Auto-excluding **/node_modules
Auto-excluding **/__pycache__
Auto-excluding .git
Searching for source files
Found 1 source file
/Users/tekumara/.virtualenvs/tmp-8a56f66a9ba27e7/test.py
  1:8 - error: Stub file not found for "botocore.exceptions" (reportMissingTypeStubs)
  5:8 - error: Type of "exceptions" is unknown (reportUnknownMemberType)
  5:8 - error: Type of "ClientError" is unknown (reportUnknownMemberType)
  5:43 - error: Type of "e" is unknown (reportUnknownVariableType)
4 errors, 0 warnings
Completed in 0.508sec

Pylance v2020.7.2

addressed in next version bug

All 5 comments

I can fix this by running pyright --createstub botocore. This creates the full set of stubs, and not only exceptions.pyi:

$ ls typings/botocore
__init__.pyi       client.pyi         credentials.pyi    eventstream.pyi    httpsession.pyi    parsers.pyi        serialize.pyi      utils.pyi
args.pyi           compat.pyi         discovery.pyi      exceptions.pyi     loaders.pyi        regions.pyi        session.pyi        validate.pyi
auth.pyi           config.pyi         docs               handlers.pyi       model.pyi          response.pyi       signers.pyi        vendored
awsrequest.pyi     configloader.pyi   endpoint.pyi       history.pyi        monitoring.pyi     retries            stub.pyi           waiter.pyi
botocore           configprovider.pyi errorfactory.pyi   hooks.pyi          paginate.pyi       retryhandler.pyi   translate.pyi

pyright 1.1.52

If you quit VS Code and restart it, does the problem go away? I'm wondering if it's a case where the language server isn't being notified that it should reset itself, clear its import resolution cache, and reanalyze.

A VSCode restart doesn't cause the issue to go away.

I can also run pyright from the CLI after creating the botocore.exceptions type stubs and it produces the reportMissingTypeStubs error too (see above).

Thanks for the bug report. I found and fixed the problem. Pyright was generating the stubs in the wrong directory when asked to create stubs for a sub-package within a top-level package. In your case, you were asking Pyright to create stubs for the "botocore.exceptions" submodule, and it was creating them within a directory called /botocore/botocore/exceptions.pyi (i.e. it duplicated the "botocore" portion of the directory structure). I've fixed the problem, and the bug should be gone with the next release of Pyright.

This is addressed in Pyright version 1.1.57, which I just published. It will also be included in the next version of Pylance.

Was this page helpful?
0 / 5 - 0 ratings