Skip to content

Make Rtree PEP 561-compliant, so that Mypy finds type hints#243

Merged
hobu merged 3 commits intoToblerity:masterfrom
oderby:master
Apr 19, 2022
Merged

Make Rtree PEP 561-compliant, so that Mypy finds type hints#243
hobu merged 3 commits intoToblerity:masterfrom
oderby:master

Conversation

@oderby
Copy link
Copy Markdown
Contributor

@oderby oderby commented Apr 18, 2022

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.

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
@oderby oderby mentioned this pull request Apr 18, 2022
Copy link
Copy Markdown
Collaborator

@adamjstewart adamjstewart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@adamjstewart
Copy link
Copy Markdown
Collaborator

Actually, I was wrong. MANIFEST.in and SOURCES.txt only correspond to what is put in the sdist, it looks like package_data is what controls what is put in the wheel. Actually, if I remove the changes to MANIFEST.in and only include the changes to setup.cfg, it looks like py.typed ends up in both the sdist and wheel. You can check this by extracting the tarball and wheel in dist/ after running python -m build.

Can you undo the last commit and remove the changes to MANIFEST.in instead? I would also be fine with keeping the changes to both, this stuff is more confusing than it should be.

@oderby
Copy link
Copy Markdown
Contributor Author

oderby commented Apr 19, 2022

Looks like the Build / Build wheel on aarch64 for cp39-* (pull_request) CI job timed out? Is there a way to re-run it?

@hobu hobu merged commit 81cc81a into Toblerity:master Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants