Skip to content

Conversation

@k4nar
Copy link
Contributor

@k4nar k4nar commented Oct 10, 2025

I’m using structlog for logging, and mypy is not happy when I’m passing my logger to one of the logging utils:

 error: Argument 1 to "before_sleep_log" has incompatible type "BoundLogger"; expected "Logger"  [arg-type]

This PR introduces a Protocol to accept anything looking like a logger.

Example:

from tenacity import before_log

import logging
before_log(logging.getLogger(), logging.INFO)


import structlog
before_log(structlog.get_logger(), logging.INFO)


import loguru
before_log(loguru.logger, logging.INFO)
$ uv run --with mypy,structlog,loguru mypy example.py
Success: no issues found in 1 source file

@mergify mergify bot merged commit d6e57dd into jd:main Oct 11, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants