added hacks for linting errors

This commit is contained in:
lla-dane
2025-07-09 13:00:14 +05:30
parent ecc443dcfe
commit 2ff5ae9c90
4 changed files with 18 additions and 17 deletions

View File

@ -1718,7 +1718,7 @@ class IPeerRecord(ABC):
"""
@abstractmethod
def to_protobuf(self) -> pb.PeerRecord:
def to_protobuf(self) -> pb.PeerRecord: # type: ignore[name-defined, attr-defined]
"""
Convert this PeerRecord into its Protobuf representation.

View File

@ -24,7 +24,7 @@ _sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n libp2p/peer/pb/peer_record.proto\x12\x07peer.pb\"\x80\x01\n\nPeerRecord\x12\x0f\n\x07peer_id\x18\x01 \x01(\x0c\x12\x0b\n\x03seq\x18\x02 \x01(\x04\x12\x32\n\taddresses\x18\x03 \x03(\x0b\x32\x1f.peer.pb.PeerRecord.AddressInfo\x1a \n\x0b\x41\x64\x64ressInfo\x12\x11\n\tmultiaddr\x18\x01 \x01(\x0c\x42*Z(github.com/libp2p/go-libp2p/core/peer/pbb\x06proto3')
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n libp2p/peer/pb/peer_record.proto\x12\x07peer.pb\"\x80\x01\n\nPeerRecord\x12\x0f\n\x07peer_id\x18\x01 \x01(\x0c\x12\x0b\n\x03seq\x18\x02 \x01(\x04\x12\x32\n\taddresses\x18\x03 \x03(\x0b\x32\x1f.peer.pb.PeerRecord.AddressInfo\x1a \n\x0b\x41\x64\x64ressInfo\x12\x11\n\tmultiaddr\x18\x01 \x01(\x0c\x42*Z(github.com/libp2p/go-libp2p/core/peer/pbb\x06proto3') # type: ignore[no-untyped-call]
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)

View File

@ -1,5 +1,6 @@
import threading
import time
from typing import Any
from multiaddr import Multiaddr
@ -72,7 +73,7 @@ class PeerRecord(IPeerRecord):
"""
return PEER_RECORD_ENVELOPE_PAYLOAD_TYPE
def to_protobuf(self) -> pb.PeerRecord:
def to_protobuf(self) -> pb.PeerRecord: # type: ignore[attr-defined, name-defined]
"""
Convert the current PeerRecord into a ProtoBuf PeerRecord message.
@ -84,7 +85,7 @@ class PeerRecord(IPeerRecord):
except Exception as e:
raise ValueError(f"failed to marshal peer_id: {e}")
msg = pb.PeerRecord()
msg = pb.PeerRecord() # type: ignore[attr-defined]
msg.peer_id = id_bytes
msg.seq = self.seq
msg.addresses.extend(addrs_to_protobuf(self.addrs))
@ -104,7 +105,7 @@ class PeerRecord(IPeerRecord):
except Exception as e:
raise ValueError(f"failed to marshal PeerRecord: {e}")
def equal(self, other) -> bool:
def equal(self, other: Any) -> bool:
"""
Check if this PeerRecord is identical to another.
@ -142,7 +143,7 @@ def unmarshal_record(data: bytes) -> PeerRecord:
if data is None:
raise ValueError("cannot unmarshal PeerRecord from None")
msg = pb.PeerRecord()
msg = pb.PeerRecord() # type: ignore[attr-defined]
try:
msg.ParseFromString(data)
except Exception as e:
@ -189,7 +190,7 @@ def peer_record_from_peer_info(info: PeerInfo) -> PeerRecord:
return record
def peer_record_from_protobuf(msg: pb.PeerRecord) -> PeerRecord:
def peer_record_from_protobuf(msg: pb.PeerRecord) -> PeerRecord: # type: ignore[attr-defined, name-defined]
"""
Convert a protobuf PeerRecord message into a PeerRecord object.
@ -208,7 +209,7 @@ def peer_record_from_protobuf(msg: pb.PeerRecord) -> PeerRecord:
return PeerRecord(peer_id, addrs, seq)
def addrs_from_protobuf(addrs: list[pb.PeerRecord.AddressInfo]) -> list[Multiaddr]:
def addrs_from_protobuf(addrs: list[pb.PeerRecord.AddressInfo]) -> list[Multiaddr]: # type: ignore[attr-defined, name-defined]
"""
Convert a list of protobuf address records to Multiaddr objects.
@ -225,7 +226,7 @@ def addrs_from_protobuf(addrs: list[pb.PeerRecord.AddressInfo]) -> list[Multiadd
return out
def addrs_to_protobuf(addrs: list[Multiaddr]) -> list[pb.PeerRecord.AddressInfo]:
def addrs_to_protobuf(addrs: list[Multiaddr]) -> list[pb.PeerRecord.AddressInfo]: # type: ignore[attr-defined, name-defined]
"""
Convert a list of Multiaddr objects into their protobuf representation.
@ -234,7 +235,7 @@ def addrs_to_protobuf(addrs: list[Multiaddr]) -> list[pb.PeerRecord.AddressInfo]
"""
out = []
for addr in addrs:
addr_info = pb.PeerRecord.AddressInfo()
addr_info = pb.PeerRecord.AddressInfo() # type: ignore[attr-defined]
addr_info.multiaddr = addr.to_bytes()
out.append(addr_info)
return out

View File

@ -15,11 +15,11 @@ from libp2p.peer.peer_record import (
def test_basic_protobuf_serializatrion_deserialization():
record = pb.PeerRecord()
record = pb.PeerRecord() # type: ignore[attr-defined]
record.seq = 1
serialized = record.SerializeToString()
new_record = pb.PeerRecord()
new_record = pb.PeerRecord() # type: ignore[attr-defined]
new_record.ParseFromString(serialized)
assert new_record.seq == 1
@ -39,10 +39,10 @@ def test_addrs_from_protobuf_multiple_addresses():
ma1 = Multiaddr("/ip4/127.0.0.1/tcp/4001")
ma2 = Multiaddr("/ip4/127.0.0.1/tcp/4002")
addr_info1 = pb.PeerRecord.AddressInfo()
addr_info1 = pb.PeerRecord.AddressInfo() # type: ignore[attr-defined]
addr_info1.multiaddr = ma1.to_bytes()
addr_info2 = pb.PeerRecord.AddressInfo()
addr_info2 = pb.PeerRecord.AddressInfo() # type: ignore[attr-defined]
addr_info2.multiaddr = ma2.to_bytes()
result = addrs_from_protobuf([addr_info1, addr_info2])
@ -51,13 +51,13 @@ def test_addrs_from_protobuf_multiple_addresses():
def test_peer_record_from_protobuf():
peer_id = ID.from_base58("QmNM23MiU1Kd7yfiKVdUnaDo8RYca8By4zDmr7uSaVV8Px")
record = pb.PeerRecord()
record = pb.PeerRecord() # type: ignore[attr-defined]
record.peer_id = peer_id.to_bytes()
record.seq = 42
for addr_str in ["/ip4/127.0.0.1/tcp/4001", "/ip4/127.0.0.1/tcp/4002"]:
ma = Multiaddr(addr_str)
addr_info = pb.PeerRecord.AddressInfo()
addr_info = pb.PeerRecord.AddressInfo() # type: ignore[attr-defined]
addr_info.multiaddr = ma.to_bytes()
record.addresses.append(addr_info)
@ -78,7 +78,7 @@ def test_to_protobuf_generates_correct_message():
record = PeerRecord(peer_id, addrs, seq)
proto = record.to_protobuf()
assert isinstance(proto, pb.PeerRecord)
assert isinstance(proto, pb.PeerRecord) # type: ignore[attr-defined]
assert proto.peer_id == peer_id.to_bytes()
assert proto.seq == seq
assert len(proto.addresses) == 1