Skip to content

feat: add name parameter to Retrying for meaningful log output#597

Merged
mergify[bot] merged 1 commit intomainfrom
devs/jd/feat/retrying-name/I717d4d3977028b499612cecb567d0ebc49b5f539
Feb 20, 2026
Merged

feat: add name parameter to Retrying for meaningful log output#597
mergify[bot] merged 1 commit intomainfrom
devs/jd/feat/retrying-name/I717d4d3977028b499612cecb567d0ebc49b5f539

Conversation

@jd
Copy link
Copy Markdown
Owner

@jd jd commented Feb 20, 2026

When using Retrying or AsyncRetrying as a context manager, log
callbacks showed '' as the function name since no fn is
set. A new name parameter allows users to provide a meaningful
identifier:

for attempt in Retrying(name='ws_listener', before_sleep=before_sleep_log(...)):
    with attempt:
        ...

RetryCallState.get_fn_name() is introduced as the single source of
truth for resolving the display name: it returns the decorated
function's qualified name when used as a decorator, falls back to
str(retry_object) in context manager mode. BaseRetrying.__str__
returns name if set, else ''. The three log helpers
(before_log, after_log, before_sleep_log) all use get_fn_name()
instead of the repeated fn is None boilerplate.

Closes #273, closes #333

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

When using `Retrying` or `AsyncRetrying` as a context manager, log
callbacks showed '<unknown>' as the function name since no `fn` is
set. A new `name` parameter allows users to provide a meaningful
identifier:

    for attempt in Retrying(name='ws_listener', before_sleep=before_sleep_log(...)):
        with attempt:
            ...

`RetryCallState.get_fn_name()` is introduced as the single source of
truth for resolving the display name: it returns the decorated
function's qualified name when used as a decorator, falls back to
`str(retry_object)` in context manager mode. `BaseRetrying.__str__`
returns `name` if set, else '<unknown>'. The three log helpers
(before_log, after_log, before_sleep_log) all use `get_fn_name()`
instead of the repeated `fn is None` boilerplate.

Closes #273, closes #333

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change-Id: I717d4d3977028b499612cecb567d0ebc49b5f539
@jd jd force-pushed the devs/jd/feat/retrying-name/I717d4d3977028b499612cecb567d0ebc49b5f539 branch from ff377e7 to 31ffdea Compare February 20, 2026 08:00
@jd jd marked this pull request as ready for review February 20, 2026 08:03
@mergify mergify Bot merged commit 70083b8 into main Feb 20, 2026
9 checks passed
@mergify mergify Bot deleted the devs/jd/feat/retrying-name/I717d4d3977028b499612cecb567d0ebc49b5f539 branch February 20, 2026 08:04
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Feb 20, 2026

Merge Queue Status

Rule: default


  • Entered queue2026-02-20 08:03 UTC
  • Checks passed · in-place
  • Merged2026-02-20 08:04 UTC · at 31ffdeadf271f67b0b82d9773c27d36319c7ba5d

This pull request spent 28 seconds in the queue, including 4 seconds running CI.

Required conditions to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant