mypy_boto3_builder: pyright: Stub file not found for "mypy_boto3_dynamodb" (reportMissingTypeStubs)

To Reproduce Steps to reproduce the behavior:

  1. Install ‘boto3-stubs[dynamodb]’
  2. Run pyright on the following code sample
import boto3
import mypy_boto3_dynamodb as dynamodb

client: dynamodb.DynamoDBClient = boto3.client("dynamodb")
  1. Actual pyright output
  2:8 - error: Stub file not found for "mypy_boto3_dynamodb" (reportMissingTypeStubs)
  4:9 - error: Type of "DynamoDBClient" is unknown (reportUnknownMemberType)
  4:41 - error: "client" is not a known member of module (reportGeneralTypeIssues)
  4:35 - error: Type of "client" is unknown (reportUnknownMemberType)
  4:1 - error: Type of "client" is unknown (reportUnknownVariableType)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16

Commits related to this issue

Most upvoted comments

Because you can create client/resource two ways

import boto3
from boto3.session import Session

# this will generate a default session for you
# before creating a client
client = boto3.client('s3')

# create a session first to share it across clients
# or override region or access keys
session = Session(...)
client = session.client('s3')

Thanks, @tekumara , your feedback helped a lot.

Okay, progress so far: https://github.com/vemel/mypy_boto3_builder/pull/47

Also, implicit type annotations should be fully supported now: https://github.com/vemel/mypy_boto3_builder/pull/47/files#diff-eeb707bbf2c07f3a17387150bca7901f

Regarding List[FilterTypeDef] - I believe this is the only correct solution in this case.

@tekumara this is awesome! I completely forgot about typings folder. Actually, I believe you can do something like

pip install --install-option="--prefix=`cwd`/typings" --ignore-installed 'boto3-stubs[ec2,sqs,compute-optimizer,ssm]'

and then do renaming.

I will cross-check if everything works correctly with *.pyi files instead of *.py (I think, imports for mypy will be broken), and release a new version.

So, the plan is:

  • rename everything to pyi
  • fix mypy imports
  • cross-check that installation to typings works as it should
  • use pre-generated client/resource overloads for all services. there are 238 overload variants, so let’s hope that pyright can handle it, because both mypy and PyCharm fail

I added initial support for pyright to boto3_stubs>=1.14.51.1. See release notes for more details and future plans.

And let me know if it still does not work as it should.

Unfortunately, this means adding all 200+ services to boto3_stubs and it takes more than 15 MB of space. Probably I can somehow let pyright know that mypy_boto3_dynamodb is a stub package, so it adds it automatically on import?

I tried pyright, works really well, so I will definitely invest some time into supporting it.

Your solution should be added to docs, or maybe I can do it in command

mypy_boto3

if pyright is installed.

Thank you for the report. I have never used pyright, but I will take a look.