Skip to content

Commit

Permalink
Remove use of Never type
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckwondo committed Apr 15, 2024
1 parent b8b0a2a commit 3a88746
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 39 deletions.
10 changes: 4 additions & 6 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, Never, Optional, Union
from .typing_ import Any, Dict, List, Optional, Union
from .utils import _validation as validate


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


def search_datasets(
count: int = -1, **kwargs: Any
) -> Union[List[DataCollection], Never]:
def search_datasets(count: int = -1, **kwargs: Any) -> List[DataCollection]:
"""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 Down Expand Up @@ -80,7 +78,7 @@ def search_datasets(
return query.get_all()


def search_data(count: int = -1, **kwargs: Any) -> Union[List[DataGranule], Never]:
def search_data(count: int = -1, **kwargs: Any) -> List[DataGranule]:
"""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 Down Expand Up @@ -166,7 +164,7 @@ def download(
local_path: Optional[str],
provider: Optional[str] = None,
threads: int = 8,
) -> Union[List[str], Never]:
) -> List[str]:
"""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 Down
13 changes: 6 additions & 7 deletions earthaccess/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from .typing_ import (
Any,
List,
Never,
Optional,
Self,
Sequence,
Expand All @@ -29,7 +28,7 @@

def get_results(
query: Union[CollectionQuery, GranuleQuery], limit: int = 2000
) -> Union[List[Any], Never]:
) -> List[Any]:
"""
Get all results up to some limit, even if spanning multiple pages.
Expand Down Expand Up @@ -108,7 +107,7 @@ def __init__(self, auth: Optional[Auth] = None, *args: Any, **kwargs: Any) -> No
self.params["include_granule_counts"] = True

@override
def hits(self) -> Union[int, Never]:
def hits(self) -> int:
"""Returns the number of hits the current query will return. This is done by
making a lightweight query to CMR and inspecting the returned headers.
Restricted datasets will always return zero results even if there are results.
Expand All @@ -131,7 +130,7 @@ def hits(self) -> Union[int, Never]:
return int(response.headers["CMR-Hits"])

@override
def get(self, limit: int = 2000) -> Union[List[DataCollection], Never]:
def get(self, limit: int = 2000) -> List[DataCollection]:
"""Get all the collections (datasets) that match with our current parameters
up to some limit, even if spanning multiple pages.
Expand Down Expand Up @@ -471,7 +470,7 @@ def __init__(self, auth: Optional[Auth] = None, *args: Any, **kwargs: Any) -> No
self._debug = False

@override
def hits(self) -> Union[int, Never]:
def hits(self) -> int:
"""Returns the number of hits the current query will return.
This is done by making a lightweight query to CMR and inspecting the returned
headers.
Expand All @@ -498,7 +497,7 @@ def hits(self) -> Union[int, Never]:
return int(response.headers["CMR-Hits"])

@override
def get(self, limit: int = 2000) -> Union[List[DataGranule], Never]:
def get(self, limit: int = 2000) -> List[DataGranule]:
"""Get all the collections (datasets) that match with our current parameters
up to some limit, even if spanning multiple pages.
Expand Down Expand Up @@ -965,7 +964,7 @@ def downloadable(self, downloadable: bool = True) -> Self:
"""
return super().downloadable(downloadable)

def doi(self, doi: str) -> Union[Self, Never]:
def doi(self, doi: str) -> Self:
"""Search data granules by DOI.
???+ Tip
Expand Down
5 changes: 1 addition & 4 deletions earthaccess/typing_.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
from typing import TypeAlias

if sys.version_info < (3, 11):
from typing import NoReturn as Never

from typing_extensions import Self
else:
from typing import Never, Self
from typing import Self

if sys.version_info < (3, 12):
from typing_extensions import override
Expand All @@ -35,7 +33,6 @@
"Dict",
"List",
"Mapping",
"Never",
"Optional",
"Self",
"Sequence",
Expand Down
40 changes: 18 additions & 22 deletions stubs/cmr/queries.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ else:
from typing import TypeAlias

if sys.version_info < (3, 11):
from typing import NoReturn as Never

from typing_extensions import Self
else:
from typing import Never, Self
from typing import Self

CMR_OPS: str
CMR_UAT: str
Expand All @@ -34,15 +32,15 @@ class Query:
headers: MutableMapping[str, str]

def __init__(self, route: str, mode: str = ...) -> None: ...
def _build_url(self) -> Union[str, Never]: ...
def get(self, limit: int = ...) -> Union[List[Any], Never]: ...
def hits(self) -> Union[int, Never]: ...
def get_all(self) -> Union[List[Any], Never]: ...
def _build_url(self) -> str: ...
def get(self, limit: int = ...) -> List[Any]: ...
def hits(self) -> int: ...
def get_all(self) -> List[Any]: ...
def parameters(self, **kwargs: Any) -> Self: ...
def format(self, output_format: str = "json") -> Union[Self, Never]: ...
def concept_id(self, ids: Sequence[str]) -> Union[Self, Never]: ...
def format(self, output_format: str = "json") -> Self: ...
def concept_id(self, ids: Sequence[str]) -> Self: ...
def provider(self, provider: str) -> Self: ...
def mode(self, mode: str = ...) -> Union[None, Never]: ...
def mode(self, mode: str = ...) -> None: ...
def token(self, token: str) -> Self: ...
def bearer_token(self, bearer_token: str) -> Self: ...

Expand All @@ -53,14 +51,12 @@ class GranuleCollectionBaseQuery(Query):
date_from: Optional[Union[str, datetime]],
date_to: Optional[Union[str, datetime]],
exclude_boundary: bool = False,
) -> Union[Self, Never]: ...
) -> Self: ...
def short_name(self, short_name: str) -> Self: ...
def version(self, version: str) -> Self: ...
def point(self, lon: FloatLike, lat: FloatLike) -> Self: ...
def circle(
self, lon: FloatLike, lat: FloatLike, dist: FloatLike
) -> Union[Self, Never]: ...
def polygon(self, coordinates: Sequence[PointLike]) -> Union[Self, Never]: ...
def circle(self, lon: FloatLike, lat: FloatLike, dist: FloatLike) -> Self: ...
def polygon(self, coordinates: Sequence[PointLike]) -> Self: ...
def bounding_box(
self,
lower_left_lon: FloatLike,
Expand All @@ -79,24 +75,24 @@ class GranuleQuery(GranuleCollectionBaseQuery):
orbit1: FloatLike,
orbit2: Optional[FloatLike] = ...,
) -> Self: ...
def day_night_flag(self, day_night_flag: str) -> Union[Self, Never]: ...
def day_night_flag(self, day_night_flag: str) -> Self: ...
def cloud_cover(
self,
min_cover: Optional[FloatLike] = ...,
max_cover: Optional[FloatLike] = ...,
) -> Self: ...
def instrument(self, instrument: str) -> Union[Self, Never]: ...
def platform(self, platform: str) -> Union[Self, Never]: ...
def sort_key(self, sort_key: str) -> Union[Self, Never]: ...
def granule_ur(self, granule_ur: str) -> Union[Self, Never]: ...
def instrument(self, instrument: str) -> Self: ...
def platform(self, platform: str) -> Self: ...
def sort_key(self, sort_key: str) -> Self: ...
def granule_ur(self, granule_ur: str) -> Self: ...

class CollectionQuery(GranuleCollectionBaseQuery):
def __init__(self, mode: str = ...) -> None: ...
def archive_center(self, center: str) -> Self: ...
def keyword(self, text: str) -> Self: ...
def native_id(self, native_ids: Sequence[str]) -> Self: ...
def tool_concept_id(self, ids: Sequence[str]) -> Union[Self, Never]: ...
def service_concept_id(self, ids: Sequence[str]) -> Union[Self, Never]: ...
def tool_concept_id(self, ids: Sequence[str]) -> Self: ...
def service_concept_id(self, ids: Sequence[str]) -> Self: ...

class ToolServiceVariableBaseQuery(Query):
def native_id(self, native_ids: Sequence[str]) -> Self: ...
Expand Down

0 comments on commit 3a88746

Please sign in to comment.