diff --git a/libp2p/pubsub/pubsub.py b/libp2p/pubsub/pubsub.py index 77f1fa7f..43fc7630 100644 --- a/libp2p/pubsub/pubsub.py +++ b/libp2p/pubsub/pubsub.py @@ -36,16 +36,16 @@ class Pubsub: router: 'IPubsubRouter' - peer_queue: asyncio.Queue[ID] + peer_queue: 'asyncio.Queue[ID]' protocols: List[str] - incoming_msgs_from_peers: asyncio.Queue[rpc_pb2.Message] - outgoing_messages: asyncio.Queue[rpc_pb2.Message] + incoming_msgs_from_peers: 'asyncio.Queue[rpc_pb2.Message]' + outgoing_messages: 'asyncio.Queue[rpc_pb2.Message]' seen_messages: LRU - my_topics: Dict[str, asyncio.Queue[rpc_pb2.Message]] + my_topics: Dict[str, 'asyncio.Queue[rpc_pb2.Message]'] # FIXME: Should be changed to `Dict[str, List[ID]]` peer_topics: Dict[str, List[str]] @@ -251,7 +251,7 @@ class Pubsub: # for each topic await self.my_topics[topic].put(publish_message) - async def subscribe(self, topic_id: str) -> asyncio.Queue[rpc_pb2.Message]: + async def subscribe(self, topic_id: str) -> 'asyncio.Queue[rpc_pb2.Message]': """ Subscribe ourself to a topic :param topic_id: topic_id to subscribe to diff --git a/libp2p/pubsub/pubsub_notifee.py b/libp2p/pubsub/pubsub_notifee.py index 5830072b..9f06176e 100644 --- a/libp2p/pubsub/pubsub_notifee.py +++ b/libp2p/pubsub/pubsub_notifee.py @@ -1,21 +1,26 @@ -import asyncio +from typing import ( + TYPE_CHECKING, +) from multiaddr import Multiaddr from libp2p.network.network_interface import INetwork from libp2p.network.notifee_interface import INotifee -from libp2p.peer.id import ID from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn from libp2p.network.stream.net_stream_interface import INetStream +if TYPE_CHECKING: + import asyncio + from libp2p.peer.id import ID + class PubsubNotifee(INotifee): # pylint: disable=too-many-instance-attributes, cell-var-from-loop, unsubscriptable-object - initiator_peers_queue: asyncio.Queue[ID] + initiator_peers_queue: 'asyncio.Queue[ID]' - def __init__(self, initiator_peers_queue: asyncio.Queue[ID]) -> None: + def __init__(self, initiator_peers_queue: 'asyncio.Queue[ID]') -> None: """ :param initiator_peers_queue: queue to add new peers to so that pubsub can process new peers after we connect to them