Skip to content
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

Type hints: PEP 561 compliance #508

Merged
merged 1 commit into from
Apr 20, 2022
Merged

Type hints: PEP 561 compliance #508

merged 1 commit into from
Apr 20, 2022

Conversation

adamjstewart
Copy link
Collaborator

Although TorchGeo has type hints, mypy isn't actually able to find them. For example, if you pip install torchgeo, then run mypy on the following file:

from torchgeo.datasets import Sentinel2

ds = Sentinel2()

you'll see the following error:

$ mypy test.py 
test.py:1: error: Skipping analyzing "torchgeo.datasets": module is installed, but missing library stubs or py.typed marker
test.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

It turns out that you have to explicitly tell mypy that your library has type hints by adding an empty py.typed file to the repo. You also need to tell setuptools to copy this file into both the sdist and wheel. See the following resources:

@adamjstewart adamjstewart added this to the 0.2.2 milestone Apr 18, 2022
@calebrob6 calebrob6 merged commit 8d5dd20 into main Apr 20, 2022
@calebrob6 calebrob6 deleted the fixes/pep561 branch April 20, 2022 15:01
remtav pushed a commit to remtav/torchgeo that referenced this pull request May 26, 2022
@adamjstewart adamjstewart modified the milestones: 0.2.2, 0.3.0 Jul 2, 2022
@adamjstewart adamjstewart mentioned this pull request Jul 11, 2022
yichiac pushed a commit to yichiac/torchgeo that referenced this pull request Apr 29, 2023
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.

None yet

2 participants