Make Rtree PEP 561-compliant, so that Mypy finds type hints#243
Make Rtree PEP 561-compliant, so that Mypy finds type hints#243hobu merged 3 commits intoToblerity:masterfrom
Conversation
After Toblerity#215, I was excited to take advantage of type hints in my projects that use Rtree. However, after upgrading to v1.0.0, mypy was giving [import errors]. According to those docs, mypy will only infer/lookup types from installed packages if they are [PEP 561] compliant. Fortunately, all that seems to [involve] is the inclusion of a `py.typed` marker file in the installed package. This PR is my attempt at doing just that. In my local testing, this seems to resolve the above Mypy import warnings. I'm new to setuptools and distributing sdist wheels though, so I'm not sure how to confirm this file will be included in the built wheels? From reading the [setuptools docs], I think this is right, but probably worth review from someone who knows these things better. [import errors]: https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports [PEP 561]: https://peps.python.org/pep-0561/ [involve]: https://mypy.readthedocs.io/en/stable/installed_packages.html#creating-pep-561-compatible-packages [setuptools docs]: https://setuptools.pypa.io/en/latest/userguide/datafiles.html
adamjstewart
left a comment
There was a problem hiding this comment.
Thanks for catching this! I think you can remove the changes to setup.cfg, but otherwise this looks good. Guess I have a few other libraries where I need to do this...
It will already be included because we added it to MANIFEST.in, so listing it here is redundant.
|
Actually, I was wrong. Can you undo the last commit and remove the changes to |
|
Looks like the |
After #215, I was excited to take advantage of type hints in my projects that
use Rtree. However, after upgrading to v1.0.0, mypy was giving import
errors. According to those docs, mypy will only infer/lookup types from
installed packages if they are PEP 561 compliant.
Fortunately, all that seems to involve is the inclusion of a
py.typedmarkerfile in the installed package. This PR is my attempt at doing just that. In my
local testing, this seems to resolve the above Mypy import warnings.
I'm new to setuptools and distributing sdist wheels though, so I'm not sure how
to confirm this file will be included in the built wheels? From reading the
setuptools docs, I think this is right, but probably worth review from someone
who knows these things better.