Skip to content

Commit

Permalink
fix(python): do not share parameters for browse methods (#4168) (gene…
Browse files Browse the repository at this point in the history
…rated) [skip ci]

Co-authored-by: Clément Vannicatte <vannicattec@gmail.com>
  • Loading branch information
algolia-bot and shortcuts committed Nov 26, 2024
1 parent 3de84ff commit 95846f6
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions clients/algoliasearch-client-python/algoliasearch/search/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,17 @@ async def browse_objects(
self,
index_name: str,
aggregator: Callable[[BrowseResponse], None],
browse_params: BrowseParamsObject = BrowseParamsObject(),
browse_params: Optional[BrowseParamsObject] = None,
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> BrowseResponse:
"""
Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
"""
browse_params.hits_per_page = browse_params.hits_per_page or 1000
if browse_params is None:
browse_params = BrowseParamsObject(hits_per_page=1000)

if browse_params.hits_per_page is None:
browse_params.hits_per_page = 1000

async def _func(_prev: Optional[BrowseResponse]) -> BrowseResponse:
if _prev is not None and _prev.cursor is not None:
Expand All @@ -376,14 +380,18 @@ async def browse_rules(
self,
index_name: str,
aggregator: Callable[[SearchRulesResponse], None],
search_rules_params: SearchRulesParams = SearchRulesParams(hits_per_page=1000),
search_rules_params: Optional[SearchRulesParams] = None,
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> SearchRulesResponse:
"""
Helper: Iterate on the `search_rules` method of the client to allow aggregating rules of an index.
"""
if search_rules_params is None:
search_rules_params = SearchRulesParams(hits_per_page=1000)

if search_rules_params.hits_per_page is None:
search_rules_params.hits_per_page = 1000

hits_per_page = search_rules_params.hits_per_page

async def _func(_prev: Optional[SearchRulesResponse]) -> SearchRulesResponse:
Expand All @@ -405,14 +413,14 @@ async def browse_synonyms(
self,
index_name: str,
aggregator: Callable[[SearchSynonymsResponse], None],
search_synonyms_params: SearchSynonymsParams = SearchSynonymsParams(
hits_per_page=1000
),
search_synonyms_params: Optional[SearchSynonymsParams] = None,
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> SearchSynonymsResponse:
"""
Helper: Iterate on the `search_synonyms` method of the client to allow aggregating synonyms of an index.
"""
if search_synonyms_params is None:
search_synonyms_params = SearchSynonymsParams(hits_per_page=1000, page=0)
hits_per_page = 1000
page = search_synonyms_params.page or 0
search_synonyms_params.hits_per_page = hits_per_page
Expand All @@ -439,13 +447,13 @@ async def _func(
async def generate_secured_api_key(
self,
parent_api_key: str,
restrictions: Optional[
Union[dict, SecuredApiKeyRestrictions]
] = SecuredApiKeyRestrictions(),
restrictions: Optional[Union[dict, SecuredApiKeyRestrictions]] = None,
) -> str:
"""
Helper: Generates a secured API key based on the given `parent_api_key` and given `restrictions`.
"""
if restrictions is None:
restrictions = SecuredApiKeyRestrictions()
restrictions_dict = {}
if isinstance(restrictions, SecuredApiKeyRestrictions):
restrictions_dict = restrictions.to_dict()
Expand Down Expand Up @@ -5365,13 +5373,17 @@ def browse_objects(
self,
index_name: str,
aggregator: Callable[[BrowseResponse], None],
browse_params: BrowseParamsObject = BrowseParamsObject(),
browse_params: Optional[BrowseParamsObject] = None,
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> BrowseResponse:
"""
Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
"""
browse_params.hits_per_page = browse_params.hits_per_page or 1000
if browse_params is None:
browse_params = BrowseParamsObject(hits_per_page=1000)

if browse_params.hits_per_page is None:
browse_params.hits_per_page = 1000

def _func(_prev: Optional[BrowseResponse]) -> BrowseResponse:
if _prev is not None and _prev.cursor is not None:
Expand All @@ -5392,14 +5404,18 @@ def browse_rules(
self,
index_name: str,
aggregator: Callable[[SearchRulesResponse], None],
search_rules_params: SearchRulesParams = SearchRulesParams(hits_per_page=1000),
search_rules_params: Optional[SearchRulesParams] = None,
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> SearchRulesResponse:
"""
Helper: Iterate on the `search_rules` method of the client to allow aggregating rules of an index.
"""
if search_rules_params is None:
search_rules_params = SearchRulesParams(hits_per_page=1000)

if search_rules_params.hits_per_page is None:
search_rules_params.hits_per_page = 1000

hits_per_page = search_rules_params.hits_per_page

def _func(_prev: Optional[SearchRulesResponse]) -> SearchRulesResponse:
Expand All @@ -5421,14 +5437,14 @@ def browse_synonyms(
self,
index_name: str,
aggregator: Callable[[SearchSynonymsResponse], None],
search_synonyms_params: SearchSynonymsParams = SearchSynonymsParams(
hits_per_page=1000
),
search_synonyms_params: Optional[SearchSynonymsParams] = None,
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> SearchSynonymsResponse:
"""
Helper: Iterate on the `search_synonyms` method of the client to allow aggregating synonyms of an index.
"""
if search_synonyms_params is None:
search_synonyms_params = SearchSynonymsParams(hits_per_page=1000, page=0)
hits_per_page = 1000
page = search_synonyms_params.page or 0
search_synonyms_params.hits_per_page = hits_per_page
Expand All @@ -5453,13 +5469,13 @@ def _func(_prev: Optional[SearchSynonymsResponse]) -> SearchSynonymsResponse:
def generate_secured_api_key(
self,
parent_api_key: str,
restrictions: Optional[
Union[dict, SecuredApiKeyRestrictions]
] = SecuredApiKeyRestrictions(),
restrictions: Optional[Union[dict, SecuredApiKeyRestrictions]] = None,
) -> str:
"""
Helper: Generates a secured API key based on the given `parent_api_key` and given `restrictions`.
"""
if restrictions is None:
restrictions = SecuredApiKeyRestrictions()
restrictions_dict = {}
if isinstance(restrictions, SecuredApiKeyRestrictions):
restrictions_dict = restrictions.to_dict()
Expand Down

0 comments on commit 95846f6

Please sign in to comment.