Skip to content

Commit 8f68969

Browse files
committed
Stop using mutable defualt args
1 parent 65ee338 commit 8f68969

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

buildkite/bazelci.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def _get_url_response(self, full_url, retries=5):
677677
for attempt in range(retries):
678678
try:
679679
response = urllib.request.urlopen(full_url)
680-
return response.read().decode("utf-8", "ignore"), response.headers
680+
return response.read().decode("utf-8", "ignore"), self._get_next_page_url(response.headers)
681681
except urllib.error.HTTPError as ex:
682682
# Handle specific error codes
683683
if ex.code == 429: # Too Many Requests
@@ -707,25 +707,28 @@ def _get_next_page_url(self, headers):
707707
match = self._NEXT_PAGE_PATTERN.search(link_header)
708708
return match.group('url') if match else None
709709

710-
def _build_url_with_params(self, url, params=[]):
710+
def _build_url_with_params(self, url, params=None):
711711
"""Builds a URL with the given query parameters."""
712+
if params is None:
713+
params = []
712714
params_str = "".join("&{}={}".format(k, v) for k, v in params)
713715
return "{}?access_token={}{}".format(url, self._token, params_str)
714716

715-
def _fetch_data_as_text(self, url, params=[], retries=5) -> str:
717+
def _fetch_data_as_text(self, url, params=None, retries=5) -> str:
716718
"""Returns the decode utf-8 representation of the _get_url_response."""
717719
url = self._build_url_with_params(url, params)
718720
return self._get_url_response(url, retries)[0]
719721

720-
def _fetch_all_pages_as_json(self, url, params=[], retries=5) -> List:
722+
def _fetch_all_pages_as_json(self, url, params=None, retries=5) -> List:
721723
"""Fetch all items iteratively across all pages."""
724+
if params is None:
725+
params = []
722726
next_url = self._build_url_with_params(url, params + [("per_page", "100")])
723727

724728
all_items = []
725729
while next_url:
726-
response, headers = self._get_url_response(next_url, retries)
730+
response, next_url = self._get_url_response(next_url, retries)
727731
all_items.extend(json.loads(response))
728-
next_url = self._get_next_page_url(headers)
729732
return all_items
730733

731734
def _get_next_page_url(self, headers):

0 commit comments

Comments
 (0)