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

feat: add py.typed for enable type checking #6

Merged
merged 1 commit into from
Jun 27, 2020
Merged

feat: add py.typed for enable type checking #6

merged 1 commit into from
Jun 27, 2020

Conversation

nekonoshiri
Copy link
Contributor

What

I added starlette/py.typed file and update setup.py to include "package_data" line.

Why

I tried to use sse-starlette with mypy, but it claims Skipping analyzing 'sse_starlette.sse': found module but no type hints or library stubs.

I found that's probably because of lack of py.typed file (PEP 561).

@sysid
Copy link
Owner

sysid commented Jun 26, 2020

Thanks nekonoshiri for your input, much appreciated!

I am not an expert on mypy, but when I run mypy --python-executable /path/to/python ./sse_starlette in the project directory I cannot reproduce your output (Actually there is no output at all, mypyreturns with code 0).

Can you tell me how to reproduce your output, please?

@nekonoshiri
Copy link
Contributor Author

Sorry for the lack of explanation.
Maybe the error occurs when installing this package by pip.

To reproduce I tried:

# I use virtualenv for reproducing environment, just to make sure
$ mkdir tmp; cd tmp
$ virtualenv -p python3.8 .
$ source bin/activate

$ pip install mypy==0.782 sse-starlette==0.3.4
$ echo "from sse_starlette import ServerSentEvent" > tmp.py
$ mypy tmp.py

Output:

tmp.py:1: error: Skipping analyzing 'sse_starlette': found module but no type hints or library stubs
tmp.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

Then:

$ pip uninstall sse-starlette
$ pip install git+https://github.com/nekonoshiri/sse-starlette.git@add-py-typed
$ mypy tmp.py

Output:

Success: no issues found in 1 source file

Ref

https://docs.python.org/3/distutils/sourcedist.html#specifying-the-files-to-distribute

encode/httpx#193

According to the above, we also need to edit MANIFEST.in file if it exists, I think.

@sysid sysid merged commit ec76804 into sysid:master Jun 27, 2020
@sysid
Copy link
Owner

sysid commented Jun 27, 2020

Thanks nekonoshiri for your contribution!

@nekonoshiri
Copy link
Contributor Author

My mypy no longer get error. Thanks!

@nekonoshiri nekonoshiri deleted the add-py-typed branch June 27, 2020 11:26
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

Successfully merging this pull request may close these issues.

2 participants