Skip to content

Commit

Permalink
Make Rtree PEP 561-compliant, so that Mypy finds type hints (#243)
Browse files Browse the repository at this point in the history
* Make Rtree PEP 561-compliant, so that Mypy finds type hints

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.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

* Remove explicit inclusion of py.typed in setup.cfg

It will already be included because we added it to MANIFEST.in, so listing it
here is redundant.

* prefer including py.typed via setuptools instead of MANIFEST.in afterall
  • Loading branch information
oderby authored Apr 19, 2022
1 parent 35e9201 commit 81cc81a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 1 deletion.
Empty file added rtree/py.typed
Empty file.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ include_package_date = True
packages = rtree

[options.package_data]
rtree = lib
rtree = lib, py.typed

[flake8]
max-line-length = 88

0 comments on commit 81cc81a

Please sign in to comment.