Skip to content

Commit

Permalink
Make PEP561 compatible
Browse files Browse the repository at this point in the history
Before, if I installed this package with pip then I couldn't actually
use mypy with it, because mypy wouldn't find the type annotations
because this wasn't structured to follow PEP561.

This follows the advice of
https://mypy.readthedocs.io/en/latest/installed_packages.html#creating-pep-561-compatible-packages

I must admit that I didn't add any tests for this. I don't think we
currently have tests that would catch typing errors? I don't understand
how the mypy extension for pytest works, I've only used mypy by itself.
It looks to me like we don't have any typing hints in the test files, so
mypy isn't even going to analyze any of those functions?

I did try installing this version locally in editable mode, and then
tested it in my separate project
(https://github.com/staticjinja/staticjinja). Before, mypy couldn't find
the type annotations for docopt, but after this change it could.
So that's one test, but really there should be other tests actually in
here to make sure that
1. The type hints are actually correct (probably via the tests/ files)
2. We are actually testing against the packaged version, not the source
  version, so that we are catching any packaging errors. This sort of
  test would have caught this problem I think.

At the very least, I don't _think_ this should break anyone? People
still will import docopt in the exact same way. Maybe there's some
small under-the-hood change that happens because of this restructuring
that will break someone?
  • Loading branch information
NickCrews committed May 27, 2022
1 parent 0a8ab02 commit de7c861
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 1 deletion.
File renamed without changes.
Empty file added docopt/py.typed
Empty file.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
license="MIT",
keywords="option arguments parsing optparse argparse getopt docopt docopt-ng",
url="https://github.com/jazzband/docopt-ng",
py_modules=["docopt"],
package_data={"docopt": ["py.typed"]},
packages=["docopt"],
long_description=open("README.md").read(),
long_description_content_type='text/markdown',
classifiers=[
Expand Down

0 comments on commit de7c861

Please sign in to comment.