Skip to content

Commit

Permalink
Make cli search function kwargs explicit (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckwondo authored Sep 26, 2023
1 parent 820ca7f commit 811f762
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
50 changes: 42 additions & 8 deletions pystac_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@

from .client import Client
from .conformance import ConformanceClasses
from .item_search import OPS
from .item_search import (
OPS,
BBoxLike,
CollectionsLike,
DatetimeLike,
FieldsLike,
FilterLangLike,
FilterLike,
IDsLike,
IntersectsLike,
QueryLike,
SortbyLike,
)
from .version import __version__
from .warnings import (
DoesNotConformTo,
Expand All @@ -26,18 +38,40 @@

def search(
client: Client,
method: str = "GET",
matched: bool = False,
save: Optional[str] = None,
**kwargs: Dict[str, Any],
*,
method: str = "GET",
max_items: Optional[int] = None,
limit: Optional[int] = None,
ids: Optional[IDsLike] = None,
collections: Optional[CollectionsLike] = None,
bbox: Optional[BBoxLike] = None,
intersects: Optional[IntersectsLike] = None,
datetime: Optional[DatetimeLike] = None,
query: Optional[QueryLike] = None,
filter: Optional[FilterLike] = None,
filter_lang: Optional[FilterLangLike] = None,
sortby: Optional[SortbyLike] = None,
fields: Optional[FieldsLike] = None,
) -> int:
"""Main function for performing a search"""

# https://github.com/python/mypy/issues/4441
# the type: ignore is to silence the mypy error
# error: Argument 2 to "search" of "Client" has incompatible
# type "**Dict[str, Dict[str, Any]]"; expected "Optional[int]" [arg-type]
result = client.search(method=method, **kwargs) # type: ignore[arg-type]
result = client.search(
method=method,
max_items=max_items,
limit=limit,
ids=ids,
collections=collections,
bbox=bbox,
intersects=intersects,
datetime=datetime,
query=query,
filter=filter,
filter_lang=filter_lang,
sortby=sortby,
fields=fields,
)

if matched:
if (nmatched := result.matched()) is not None:
Expand Down
2 changes: 1 addition & 1 deletion pystac_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def search(

if not self.conforms_to(ConformanceClasses.ITEM_SEARCH):
raise DoesNotConformTo(
"ITEM_SEARCH", "There is not fallback option available for search."
"ITEM_SEARCH", "There is no fallback option available for search."
)

return ItemSearch(
Expand Down

0 comments on commit 811f762

Please sign in to comment.