From 7bc5d5b53fa2192b394836fbb3489115f5419f17 Mon Sep 17 00:00:00 2001 From: "claude-agentic-bot[bot]" <338008168+claude-agentic-bot[bot]@users.noreply.github.com> Date: Mon, 5 Oct 2026 08:07:14 +0000 Subject: [PATCH] fix: avoid mutable default args and shared exception instance in githost/retry helpers --- bert_e/git_host/base.py | 16 +++++++++++----- bert_e/lib/retry.py | 5 ++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/bert_e/git_host/base.py b/bert_e/git_host/base.py index a38ab926..c6c911a3 100644 --- a/bert_e/git_host/base.py +++ b/bert_e/git_host/base.py @@ -115,7 +115,7 @@ def __init__(self, client=None, _validate=True, **data): self.data = data @classmethod - def get(cls, client, url=None, params={}, headers={}, **kwargs): + def get(cls, client, url=None, params=None, headers=None, **kwargs): """Get a Githost object. The result is parsed using cls.GET_SCHEMA, of cls.SCHEMA if absent. @@ -129,6 +129,8 @@ def get(cls, client, url=None, params={}, headers={}, **kwargs): Returns: The result of the query, parsed by the shema. """ + params = params or {} + headers = headers or {} url = url or cls.GET_URL if url is None: raise InvalidOperation( @@ -141,7 +143,7 @@ def get(cls, client, url=None, params={}, headers={}, **kwargs): return obj @classmethod - def list(cls, client, url=None, params={}, headers={}, **kwargs): + def list(cls, client, url=None, params=None, headers=None, **kwargs): """List objects. The result is parsed using cls.LIST_SCHEMA, or cls.GET_SCHEMA if @@ -154,6 +156,8 @@ def list(cls, client, url=None, params={}, headers={}, **kwargs): The elements of the response as they are parsed by the schema. """ + params = params or {} + headers = headers or {} url = url or cls.LIST_URL if url is None: raise InvalidOperation( @@ -180,8 +184,9 @@ def load(cls, data, schema_cls=None, **kwargs): return cls(**load_schema(schema_cls, data, **kwargs), _validate=False) @classmethod - def create(cls, client, data, headers={}, url=None, **kwargs): + def create(cls, client, data, headers=None, url=None, **kwargs): """Create an object.""" + headers = headers or {} url = url or cls.CREATE_URL if url is None: raise InvalidOperation( @@ -196,12 +201,13 @@ def create(cls, client, data, headers={}, url=None, **kwargs): return obj @classmethod - def update(cls, client, data, headers={}, url=None, **kwargs): + def update(cls, client, data, headers=None, url=None, **kwargs): """Update an object.""" + headers = headers or {} url = url or cls.UPDATE_URL or cls.GET_URL if url is None: raise InvalidOperation( - 'CREATE is not supported on {} objects.'.format(cls.__name__)) + 'UPDATE is not supported on {} objects.'.format(cls.__name__)) create_schema_cls = cls.UPDATE_SCHEMA or cls.SCHEMA json = dump_schema(create_schema_cls, data) diff --git a/bert_e/lib/retry.py b/bert_e/lib/retry.py index 640bbaec..b84dbad7 100644 --- a/bert_e/lib/retry.py +++ b/bert_e/lib/retry.py @@ -45,7 +45,7 @@ def reset(self): self._cur_delay = 1 self._elapsed = 0 - def wait(self, err=RetryTimeout()): + def wait(self, err=None): """Wait until next retry. If wait limit was exceeded (first try happened more than `limit` @@ -61,7 +61,7 @@ def wait(self, err=RetryTimeout()): if self.limit is not None and self._elapsed >= self.limit: if self._log: self._log.error("Reached timeout (%ds)", self.limit) - raise err + raise err if err is not None else RetryTimeout() sleep(self._cur_delay) self._elapsed += self._cur_delay self._cur_delay = min(self._max_delay, self._cur_delay * 2) @@ -80,7 +80,6 @@ def run(self, func, *args, **kwargs): the result of func(*args, **kwargs) """ - # Python 2 doesn't support mixing optional args with **kwargs syntax catch = kwargs.pop('catch', Exception) fail_msg = kwargs.pop('fail_msg', "Call to '%s' failed" % func.__name__)