Skip to content

Commit d44f462

Browse files
committed
fixed linting errors
1 parent 7520b4d commit d44f462

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

multiaddr/codecs/memory.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
import struct
2+
from typing import Any
3+
24
from ..codecs import CodecBase
35
from ..exceptions import BinaryParseError
46

57
SIZE = 64
68
IS_PATH = False
79

10+
811
class Codec(CodecBase):
912
SIZE = SIZE
1013
IS_PATH = IS_PATH
11-
12-
def to_bytes(self, proto, string: str) -> bytes:
13-
# Parse as unsigned 64-bit int
14-
value = int(string, 10)
15-
if value < 0 or value > 0xFFFFFFFFFFFFFFFF:
16-
raise ValueError("Value out of range for uint64")
17-
return struct.pack(">Q", value) # big-endian uint64
1814

19-
def to_string(self, proto, buf: bytes) -> str:
15+
def to_bytes(self, proto: Any, string: str) -> bytes:
16+
# Parse as unsigned 64-bit int
17+
value = int(string, 10)
18+
if value < 0 or value > 0xFFFFFFFFFFFFFFFF:
19+
raise ValueError("Value out of range for uint64")
20+
return struct.pack(">Q", value) # big-endian uint64
21+
22+
def to_string(self, proto: Any, buf: bytes) -> str:
2023
if len(buf) != 8:
2124
raise BinaryParseError("Expected 8 bytes for uint64", buf, "memory")
2225
value = struct.unpack(">Q", buf)[0]
2326
return str(value)
24-
27+
2528
def memory_validate(self, b: bytes) -> None:
2629
if len(b) != 8:
2730
raise ValueError(f"Invalid length: must be exactly 8 bytes, got {len(b)}")
28-

multiaddr/protocols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def __repr__(self) -> str:
167167
Protocol(P_P2P_CIRCUIT, "p2p-circuit", None),
168168
Protocol(P_WEBTRANSPORT, "webtransport", None),
169169
Protocol(P_UNIX, "unix", "fspath"),
170-
Protocol(P_MEMORY, "memory", None)
170+
Protocol(P_MEMORY, "memory", None),
171171
]
172172

173173

tests/test_codec.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
import struct
32

43
from multiaddr.codecs import memory
54
from multiaddr.exceptions import BinaryParseError
@@ -19,6 +18,7 @@ def test_to_bytes_and_to_string_roundtrip():
1918
out = codec.to_string(None, b)
2019
assert out == s
2120

21+
2222
def test_invalid_string_to_bytes():
2323
codec = memory.Codec()
2424

@@ -34,6 +34,7 @@ def test_invalid_string_to_bytes():
3434
with pytest.raises(ValueError):
3535
codec.to_bytes(None, str(2**64))
3636

37+
3738
def test_invalid_bytes_to_string():
3839
codec = memory.Codec()
3940

@@ -54,6 +55,7 @@ def test_specific_encoding():
5455
assert codec.to_bytes(None, "42") == expected_bytes
5556
assert codec.to_string(None, expected_bytes) == "42"
5657

58+
5759
def test_memory_validate_function():
5860
# Directly test the helper
5961
codec = memory.Codec()
@@ -63,4 +65,4 @@ def test_memory_validate_function():
6365

6466
# Invalid length
6567
with pytest.raises(ValueError):
66-
codec.memory_validate(b"\x00" * 7)
68+
codec.memory_validate(b"\x00" * 7)

0 commit comments

Comments
 (0)