sysid / sse-starlette

BSD 3-Clause "New" or "Revised" License
505 stars 36 forks source link

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

Closed nekonoshiri closed 4 years ago

nekonoshiri commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Thanks nekonoshiri for your contribution!

nekonoshiri commented 4 years ago

My mypy no longer get error. Thanks!