Skip to content

Commit

Permalink
Cleanup return types and docstrings
Browse files Browse the repository at this point in the history
- wrap docstrings at 88 characters per ruff configuration
- remove `Never` from return types where method raises only for invalid input types or values
- add missing `Never` return types where method raises for server-side errors
  • Loading branch information
chuckwondo committed Apr 15, 2024
1 parent 919dbfa commit b8b0a2a
Show file tree
Hide file tree
Showing 2 changed files with 233 additions and 187 deletions.
19 changes: 15 additions & 4 deletions earthaccess/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .results import DataCollection, DataGranule
from .search import CollectionQuery, DataCollections, DataGranules, GranuleQuery
from .store import Store
from .typing_ import Any, Dict, List, Optional, Union
from .typing_ import Any, Dict, List, Never, Optional, Union
from .utils import _validation as validate


Expand All @@ -27,7 +27,9 @@ def _normalize_location(location: Optional[str]) -> Optional[str]:
return location


def search_datasets(count: int = -1, **kwargs: Any) -> List[DataCollection]:
def search_datasets(
count: int = -1, **kwargs: Any
) -> Union[List[DataCollection], Never]:
"""Search datasets using NASA's CMR.
[https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html](https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html)
Expand All @@ -51,6 +53,9 @@ def search_datasets(count: int = -1, **kwargs: Any) -> List[DataCollection]:
A list of DataCollection results that can be used to get information about a
dataset, e.g. concept_id, doi, etc.
Raises:
RuntimeError: The CMR query failed.
Examples:
```python
datasets = earthaccess.search_datasets(
Expand All @@ -75,7 +80,7 @@ def search_datasets(count: int = -1, **kwargs: Any) -> List[DataCollection]:
return query.get_all()


def search_data(count: int = -1, **kwargs: Any) -> List[DataGranule]:
def search_data(count: int = -1, **kwargs: Any) -> Union[List[DataGranule], Never]:
"""Search dataset granules using NASA's CMR.
[https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html](https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html)
Expand All @@ -99,6 +104,9 @@ def search_data(count: int = -1, **kwargs: Any) -> List[DataGranule]:
a list of DataGranules that can be used to access the granule files by using
`download()` or `open()`.
Raises:
RuntimeError: The CMR query failed.
Examples:
```python
datasets = earthaccess.search_data(
Expand Down Expand Up @@ -158,7 +166,7 @@ def download(
local_path: Optional[str],
provider: Optional[str] = None,
threads: int = 8,
) -> List[str]:
) -> Union[List[str], Never]:
"""Retrieves data granules from a remote storage system.
* If we run this in the cloud, we will be using S3 to move data to `local_path`.
Expand All @@ -173,6 +181,9 @@ def download(
Returns:
List of downloaded files
Raises:
Exception: A file download failed.
"""
provider = _normalize_location(provider)
if isinstance(granules, DataGranule):
Expand Down
Loading

0 comments on commit b8b0a2a

Please sign in to comment.