-
-
Notifications
You must be signed in to change notification settings - Fork 318
fix: format traceback inline for loguru compatibility #622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |||
| # See the License for the specific language governing permissions and | ||||
| # limitations under the License. | ||||
|
|
||||
| import traceback | ||||
| import typing | ||||
|
|
||||
| from tenacity import _utils | ||||
|
|
@@ -35,8 +36,6 @@ def before_sleep_log( | |||
| """Before sleep strategy that logs to some logger the attempt.""" | ||||
|
|
||||
| def log_it(retry_state: "RetryCallState") -> None: | ||||
| local_exc_info: BaseException | bool | None | ||||
|
|
||||
| if retry_state.outcome is None: | ||||
| raise RuntimeError("log_it() called before outcome was set") | ||||
|
|
||||
|
|
@@ -46,22 +45,22 @@ def log_it(retry_state: "RetryCallState") -> None: | |||
| if retry_state.outcome.failed: | ||||
| ex = retry_state.outcome.exception() | ||||
| verb, value = "raised", f"{ex.__class__.__name__}: {ex}" | ||||
|
|
||||
| if exc_info: | ||||
| local_exc_info = retry_state.outcome.exception() | ||||
| else: | ||||
| local_exc_info = False | ||||
| else: | ||||
| verb, value = "returned", retry_state.outcome.result() | ||||
| local_exc_info = False # exc_info does not apply when no exception | ||||
|
|
||||
| fn_name = retry_state.get_fn_name() | ||||
|
|
||||
| logger.log( | ||||
| log_level, | ||||
| msg = ( | ||||
| f"Retrying {fn_name} " | ||||
| f"in {sec_format % retry_state.next_action.sleep} seconds as it {verb} {value}.", | ||||
| exc_info=local_exc_info, | ||||
| f"in {sec_format % retry_state.next_action.sleep} seconds as it {verb} {value}." | ||||
| ) | ||||
|
|
||||
| if exc_info and retry_state.outcome.failed: | ||||
| ex = retry_state.outcome.exception() | ||||
|
||||
| ex = retry_state.outcome.exception() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing
**kwargsfromLoggerProtocol.log()is a breaking API change for any users who have custom logger implementations typed against this protocol. The previous signature wasdef log(self, level: int, msg: str, *args: Any, **kwargs: Any) -> Any, which matched the broaderlogging.Logger.logsignature that acceptsstacklevel,extra, etc. as keyword arguments. Users who previously passed such keyword arguments through aLoggerProtocol-typed reference will now get a static type error. Consider whether a more conservative change (keeping**kwargsin the protocol even if tenacity itself no longer passes kwargs) would be preferable for backward compatibility.