-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add py.typed #29
base: master
Are you sure you want to change the base?
Add py.typed #29
Conversation
@@ -31,5 +31,8 @@ | |||
entry_points={ | |||
'console_scripts': ['apertium-streamparser=streamparser:main'], | |||
}, | |||
package_data={ | |||
'streamparser': ['py.typed'], | |||
}, | |||
py_modules=['streamparser'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.py
is incorrect in some way and preventing thepy.typed
from being picked up or there's an incompatibility withpy_modules.