Skip to content

Commit dcb7a4f

Browse files
fix: use stacklevel=2 in AssignRequest deprecation warning
stacklevel=3 pointed at the wrong caller frame when encode_body() was called directly (e.g. not via Message.encode()). stacklevel=2 is the conventional Python default and correctly points at the immediate caller of encode_body() in all call paths. Closes #153. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e8bd03c commit dcb7a4f

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/dqlitewire/messages/requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def encode_body(self) -> bytes:
446446
"(1-word body). Modern dqlite servers and the Go client always send "
447447
"both node_id and role. Use role=0 (VOTER) for equivalent behavior.",
448448
DeprecationWarning,
449-
stacklevel=3,
449+
stacklevel=2,
450450
)
451451
return result
452452

tests/test_messages_requests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,18 @@ def test_encode_without_role_emits_deprecation_warning(self) -> None:
365365
assert issubclass(w[0].category, DeprecationWarning)
366366
assert "legacy" in str(w[0].message).lower() or "promote" in str(w[0].message).lower()
367367

368+
def test_encode_without_role_warning_points_at_encode_body_caller(self) -> None:
369+
"""153: stacklevel should point at the caller of encode_body()."""
370+
import warnings
371+
372+
msg = AssignRequest(node_id=1)
373+
with warnings.catch_warnings(record=True) as w:
374+
warnings.simplefilter("always")
375+
# Call encode_body() directly — the warning should point here.
376+
msg.encode_body()
377+
assert len(w) == 1
378+
assert w[0].filename == __file__
379+
368380
def test_encode_with_role_no_warning(self) -> None:
369381
"""Encoding AssignRequest with role should not warn."""
370382
import warnings

0 commit comments

Comments
 (0)