From 16d0ed56cf2f3d8e6401579c4765cc12f9d280ef Mon Sep 17 00:00:00 2001 From: ibondarenko1 Date: Fri, 24 Apr 2026 11:38:36 -0700 Subject: [PATCH] sdp: address review nits (import at top, InvalidPacketError) - bumble/sdp.py: replace raise ValueError with raise InvalidPacketError in DataElement.list_from_bytes depth guard. InvalidPacketError already imported at line 34 and extends ValueError so the existing regression test continues to match. - tests/sdp_test.py: remove duplicate 'import pytest' inside test_nested_sequence_recursion_guard; pytest already imported at module top (line 23). Threading.local counter left as-is per zxzxwu's 'leave it here and refactor later' comment on the PR. --- bumble/sdp.py | 2 +- tests/sdp_test.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/bumble/sdp.py b/bumble/sdp.py index 07571a2..6ffce32 100644 --- a/bumble/sdp.py +++ b/bumble/sdp.py @@ -294,7 +294,7 @@ class DataElement: def list_from_bytes(data): depth = getattr(_parse_state, "depth", 0) if depth >= _MAX_DATA_ELEMENT_NESTING: - raise ValueError( + raise InvalidPacketError( f"SDP data element nesting exceeds max depth " f"({_MAX_DATA_ELEMENT_NESTING})" ) diff --git a/tests/sdp_test.py b/tests/sdp_test.py index a8d62a0..5e9708b 100644 --- a/tests/sdp_test.py +++ b/tests/sdp_test.py @@ -461,8 +461,6 @@ def test_nested_sequence_recursion_guard(): break inner = bytes([0x36, (size >> 8) & 0xFF, size & 0xFF]) + inner - import pytest - with pytest.raises(ValueError, match="nesting exceeds max depth"): DataElement.from_bytes(inner)