Skip to content

Commit 9cc6350

Browse files
thomas-manginclaude
andcommitted
refactor: Remove unnecessary bytes() conversions for Buffer comparisons
Eliminate 3 redundant bytes() conversions where memoryview comparison works directly: - BGP marker check: memoryview slice compares correctly with bytes - NextHop empty check: truthiness works for both bytes and memoryview 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent da29a81 commit 9cc6350

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/exabgp/bgp/message/update/attribute/nexthop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def pack_attribute(self, negotiated: Negotiated) -> bytes:
129129

130130
@classmethod
131131
def unpack_attribute(cls, data: Buffer, negotiated: Negotiated) -> 'NextHop | IP':
132-
if not bytes(data):
132+
if not data:
133133
return IP.NoNextHop
134134
return cls.from_packet(data)
135135

src/exabgp/reactor/network/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def reader(self) -> Iterator[tuple[int, int, Buffer, Buffer, NotifyError | None]
384384
if not header:
385385
yield 0, 0, memoryview(b''), memoryview(b''), None
386386

387-
if not bytes(header[:16]) == Message.MARKER:
387+
if header[:16] != Message.MARKER:
388388
report = 'The packet received does not contain a BGP marker'
389389
yield 0, 0, header, memoryview(b''), NotifyError(1, 1, report)
390390
return
@@ -428,7 +428,7 @@ async def reader_async(self) -> tuple[int, int, Buffer, Buffer, NotifyError | No
428428
# Read BGP header (19 bytes)
429429
header = await self._reader_async(Message.HEADER_LEN)
430430

431-
if not bytes(header[:16]) == Message.MARKER:
431+
if header[:16] != Message.MARKER:
432432
report = 'The packet received does not contain a BGP marker'
433433
return 0, 0, header, memoryview(b''), NotifyError(1, 1, report)
434434

0 commit comments

Comments
 (0)