Conversation
| package_data={ | ||
| 'streamparser': ['py.typed'], | ||
| }, | ||
| py_modules=['streamparser'], |
There was a problem hiding this comment.
You need to add zip_safe=False otherwise setuptools will make an egg and mypy doesn't work with that.
There was a problem hiding this comment.
Thanks for the suggestion! I tried this out and didn't have much luck.
$ make -B dist
python3 setup.py sdist
running sdist
running egg_info
...
creating apertium-streamparser-5.0.3
creating apertium-streamparser-5.0.3/apertium_streamparser.egg-info
copying files to apertium-streamparser-5.0.3...
copying LICENSE -> apertium-streamparser-5.0.3
copying MANIFEST.in -> apertium-streamparser-5.0.3
copying README.md -> apertium-streamparser-5.0.3
copying py.typed -> apertium-streamparser-5.0.3
copying setup.py -> apertium-streamparser-5.0.3
copying streamparser.py -> apertium-streamparser-5.0.3
...
Creating tar archive
removing 'apertium-streamparser-5.0.3' (and everything under it)
$ pip3 install /Users/Sushain/Documents/streamparser/dist/apertium-streamparser-5.0.3.tar.gz
...
Successfully built apertium-streamparser
Installing collected packages: apertium-streamparser
Successfully installed apertium-streamparser-5.0.3
$ python3
>>> import streamparser
>>> streamparser.parse
<function parse at 0x104b36950>
$ cat $(which mypy)
#!/usr/local/opt/python/bin/python3.7
# -*- coding: utf-8 -*-
import re
import sys
from mypy.__main__ import console_entry
...
$ cat test.py
import streamparser
reveal_type(streamparser.parse)
$ mypy test.py
test.py:1: error: Cannot find module named 'streamparser'
test.py:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
test.py:3: error: Revealed type is 'Any'
There was a problem hiding this comment.
Oh! I missed the py_modules bit. PEP 561 won't work with py_modules. (Also package_data won't work as your code is right now since there isn't a streamparser package, just a module).
You can either switch streamparser to a package, or make a stub file in a stub package.
There was a problem hiding this comment.
Alas, I had a suspicion single-file modules and py.typed wouldn't cooperate. The best strategy is probably to just create a real (temporary) package with the source at make-time (just to keep this repo from having a somewhat overkill src folder).
Thanks for your help and confirming this strategy doesn't work!
This doesn't seem to actually work as it should, unfortunately... Maybe the
setup.pyis incorrect in some way and preventing thepy.typedfrom being picked up or there's an incompatibility withpy_modules.