Fix type hints except pb msg in pubsub folder

This commit is contained in:
NIC619
2019-07-27 11:27:47 +08:00
parent a0aa105867
commit b2f496d081
6 changed files with 79 additions and 73 deletions

View File

@ -22,8 +22,8 @@ from libp2p.host.host_interface import (
from libp2p.peer.id import (
ID,
)
from libp2p.network.stream.net_stream_interface import (
INetStream,
from libp2p.network.stream.net_stream import (
NetStream,
)
@ -109,7 +109,7 @@ class Pubsub:
self.peer_topics = {}
# Create peers map, which maps peer_id (as string) to stream (to a given peer)
# FIXME: Should be changed to `Dict[ID, INetStream]`
# FIXME: Should be changed to `Dict[ID, NetStream]`
self.peers = {}
self.counter = time.time_ns()
@ -130,7 +130,7 @@ class Pubsub:
return packet.SerializeToString()
async def continuously_read_stream(self, stream: INetStream) -> None:
async def continuously_read_stream(self, stream: NetStream) -> None:
"""
Read from input stream in an infinite loop. Process
messages from other nodes
@ -168,7 +168,7 @@ class Pubsub:
# Force context switch
await asyncio.sleep(0)
async def stream_handler(self, stream: INetStream) -> None:
async def stream_handler(self, stream: NetStream) -> None:
"""
Stream handler for pubsub. Gets invoked whenever a new stream is created
on one of the supported pubsub protocols.
@ -196,12 +196,13 @@ class Pubsub:
"""
while True:
peer_id: ID = await self.peer_queue.get()
# FIXME: Should be changed to type 'ID'
peer_id: str = await self.peer_queue.get()
# Open a stream to peer on existing connection
# (we know connection exists since that's the only way
# an element gets added to peer_queue)
stream: INetStream = await self.host.new_stream(peer_id, self.protocols)
stream: NetStream = await self.host.new_stream(peer_id, self.protocols)
# Add Peer
# Map peer to stream