Skip to content

Commit 66388d2

Browse files
committed
Dispatch warn level to logging.warning, not deprecated .warn (#89)
On the asyncio backend, _log() did `getattr(logger._logger, level)(msg)` with level == "warn", which resolves to logging.Logger.warn — the deprecated alias of .warning — emitting "DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead". Remap the "warn" level name to "warning" for stdlib dispatch, mirroring the existing "trace" -> "debug" handling, while keeping the txaio-facing level name "warn" in kwargs["log_level"]. The Twisted backend is unaffected (it maps to LogLevel.warn, not stdlib method names). Add a cross-backend regression test (test_warn) that turns DeprecationWarning into an error and asserts the message is emitted. Verified red before the fix (asyncio) and green after, both backends. Note: This work was completed with AI assistance (Claude Code).
1 parent 53eb204 commit 66388d2

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ This document contains a reverse-chronological list of changes to txaio.
1111
26.6.1
1212
------
1313

14+
**Fix**
15+
16+
* Logging at ``warn`` level on the asyncio backend no longer triggers a ``DeprecationWarning`` from the standard library: ``txaio`` now dispatches the ``warn`` level to ``logging.Logger.warning`` instead of the deprecated ``.warn`` alias (`#89 <https://github.com/crossbario/txaio/issues/89>`_)
17+
1418
**Other**
1519

1620
* Bumped the shared ``wamp-ai`` and ``wamp-cicd`` Git submodules to match the rest of the WAMP project group (zlmdb / autobahn-python 26.6.1) for the coordinated release. The ``wamp-cicd`` bump picks up the GHSA-6658 shell-injection hardening in the shared ``identifiers.yml`` reusable workflow (untrusted GitHub event fields are now passed via ``env:`` as quoted data with a fail-closed branch-name allowlist) (`#218 <https://github.com/crossbario/txaio/issues/218>`_)

src/txaio/aio.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ def _log(logger, level, format="", **kwargs):
162162
if level == "trace":
163163
level = "debug"
164164
kwargs["txaio_trace"] = True
165+
elif level == "warn":
166+
# stdlib logging.Logger.warn() is the deprecated alias of .warning();
167+
# dispatch to the non-deprecated method to avoid a DeprecationWarning (#89)
168+
level = "warning"
165169

166170
msg = format.format(**kwargs)
167171
getattr(logger._logger, level)(msg)

tests/test_logging.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,28 @@ def test_info(handler, framework):
139139
assert handler.messages[0].endswith(b"hilarious elephant")
140140

141141

142+
def test_warn(handler, framework):
143+
"""
144+
Logging at "warn" level emits the message and must not trigger the
145+
deprecated stdlib ``logging.Logger.warn`` alias (#89): on the asyncio
146+
backend the level name is dispatched to ``.warning``, not ``.warn``.
147+
"""
148+
import warnings
149+
150+
logger = txaio.make_logger()
151+
152+
with warnings.catch_warnings():
153+
warnings.simplefilter("error", DeprecationWarning)
154+
logger.warn(
155+
"{adjective} {nouns[0]}",
156+
adjective="hilarious",
157+
nouns=["skunk", "elephant", "wombat"],
158+
)
159+
160+
assert len(handler.messages) == 1
161+
assert handler.messages[0].endswith(b"hilarious skunk")
162+
163+
142164
def test_legacy_error_with_traceback(handler, framework):
143165
if framework.using_twisted:
144166
return pytest.skip("test only for asyncio users")

0 commit comments

Comments
 (0)