Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy doesn't seem to detect this package #13

Open
d33tah opened this issue Oct 31, 2019 · 5 comments
Open

mypy doesn't seem to detect this package #13

d33tah opened this issue Oct 31, 2019 · 5 comments

Comments

@d33tah
Copy link

d33tah commented Oct 31, 2019

Consider the following test file:

import boto3
from boto3_type_annotations.s3 import Bucket
bucket: Bucket = boto3.resource("s3").Bucket('asd')

And the following Dockerfile:

FROM python:3.7
RUN pip install boto3 boto3_type_annotations mypy
ADD ./a.py a.py
RUN mypy a.py

Here's what happens when I try to run it:

> sudo docker build . 
Sending build context to Docker daemon  3.072kB
Step 1/4 : FROM python:3.7
 ---> 023b89039ba4
Step 2/4 : RUN pip install boto3 boto3_type_annotations mypy
 ---> Using cache
 ---> f3145ded7f54
Step 3/4 : ADD ./a.py a.py
 ---> Using cache
 ---> d90f377d6b3e
Step 4/4 : RUN mypy a.py
 ---> Running in 6e8e8b383b62
a.py:1: error: No library stub file for module 'boto3'
a.py:1: note: (Stub files are from https://github.com/python/typeshed)
a.py:2: error: Cannot find module named 'boto3_type_annotations.s3'
a.py:2: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 2 errors in 1 file (checked 1 source file)
The command '/bin/sh -c mypy a.py' returned a non-zero code: 1

Is this intentional that this package doesn't seem to work with mypy, or am I doing something wrong?

@ethanhs
Copy link

ethanhs commented Nov 1, 2019

It looks like the package is missing a PEP 561 py.typed file (see https://mypy.readthedocs.io/en/latest/installed_packages.html#making-pep-561-compatible-packages).

@d33tah
Copy link
Author

d33tah commented Nov 1, 2019

@ethanhs thanks! Not sure if I understand the documentation correctly though - does the py.typed file have to have any specific contents, or is it enough for it to be empty?

@ethanhs
Copy link

ethanhs commented Nov 1, 2019

@d33tah empty is fine!

@vemel
Copy link

vemel commented Nov 6, 2019

Just added a PR. Works great.

Thank you, guys!

@vemel
Copy link

vemel commented Nov 9, 2019

I created a fork mypy-boto3 that supports mypy.
Some extra features:

  • mypy compatibility as a main goal
  • real type annotations. With boto3 naming style string annotations do not work
  • subresources are included
  • modularity, so you can install only services you use with or without docs
  • full boto3 docs included and cleaned up
  • black-formatted source code for easier reading

I welcome any feedback. Also, if someone can help with adding typing for return values and dict arguments - that would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants