Skip to content

Commit

Permalink
provide default instance only if not already provided in args
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Mar 5, 2025
1 parent 3724120 commit e793888
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions jg/hen/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@
def with_github(fn: Callable[..., Coroutine]) -> Callable[..., Coroutine]:
@wraps(fn)
async def wrapper(*args, **kwargs) -> Coroutine:
github_api_key = kwargs.pop("github_api_key", None)
async with GitHub(github_api_key, user_agent=USER_AGENT) as github:
return await fn(*args, github=github, **kwargs)
if github_api_key := kwargs.pop("github_api_key", None):
async with GitHub(github_api_key, user_agent=USER_AGENT) as github:
return await fn(*args, github=github, **kwargs)
else:
return await fn(*args, **kwargs)

return wrapper


def with_http(fn: Callable[..., Coroutine]) -> Callable[..., Coroutine]:
@wraps(fn)
async def wrapper(*args, **kwargs) -> Coroutine:
async with httpx.AsyncClient(
follow_redirects=True, headers={"User-Agent": USER_AGENT}
) as client:
return await fn(*args, http=client, **kwargs)
if kwargs.get("http", None):
return await fn(*args, **kwargs)
else:
async with httpx.AsyncClient(
follow_redirects=True, headers={"User-Agent": USER_AGENT}
) as client:
return await fn(*args, http=client, **kwargs)

return wrapper

0 comments on commit e793888

Please sign in to comment.