mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
fix: improve types according to new typecheck
This commit is contained in:
@ -193,7 +193,7 @@ async def run_enhanced_demo(
|
|||||||
print("🖥️ ENHANCED ECHO SERVER MODE")
|
print("🖥️ ENHANCED ECHO SERVER MODE")
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
|
|
||||||
# Set the enhanced stream handler
|
# type: ignore: Stream is type of NetStream
|
||||||
host.set_stream_handler(PROTOCOL_ID, enhanced_echo_handler)
|
host.set_stream_handler(PROTOCOL_ID, enhanced_echo_handler)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
@ -217,7 +217,8 @@ async def run_enhanced_demo(
|
|||||||
|
|
||||||
# Create stream and run enhanced demo
|
# Create stream and run enhanced demo
|
||||||
stream = await host.new_stream(info.peer_id, [PROTOCOL_ID])
|
stream = await host.new_stream(info.peer_id, [PROTOCOL_ID])
|
||||||
await enhanced_client_demo(stream)
|
if isinstance(stream, NetStream):
|
||||||
|
await enhanced_client_demo(stream)
|
||||||
|
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
print("CLIENT DEMO COMPLETE")
|
print("CLIENT DEMO COMPLETE")
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
from enum import (
|
from enum import (
|
||||||
Enum,
|
Enum,
|
||||||
)
|
)
|
||||||
from typing import (
|
|
||||||
Optional,
|
|
||||||
)
|
|
||||||
|
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
@ -102,11 +99,11 @@ class NetStream(INetStream):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
muxed_stream: IMuxedStream
|
muxed_stream: IMuxedStream
|
||||||
protocol_id: Optional[TProtocol]
|
protocol_id: TProtocol | None
|
||||||
__stream_state: StreamState
|
__stream_state: StreamState
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, muxed_stream: IMuxedStream, nursery: Optional[trio.Nursery] = None
|
self, muxed_stream: IMuxedStream, nursery: trio.Nursery | None = None
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
@ -142,7 +139,7 @@ class NetStream(INetStream):
|
|||||||
async with self._state_lock:
|
async with self._state_lock:
|
||||||
return self.__stream_state
|
return self.__stream_state
|
||||||
|
|
||||||
async def read(self, n: Optional[int] = None) -> bytes:
|
async def read(self, n: int | None = None) -> bytes:
|
||||||
"""
|
"""
|
||||||
Read from stream.
|
Read from stream.
|
||||||
|
|
||||||
@ -279,7 +276,7 @@ class NetStream(INetStream):
|
|||||||
if hasattr(swarm, "refs") and hasattr(swarm.refs, "done"):
|
if hasattr(swarm, "refs") and hasattr(swarm.refs, "done"):
|
||||||
swarm.refs.done()
|
swarm.refs.done()
|
||||||
|
|
||||||
def get_remote_address(self) -> Optional[tuple[str, int]]:
|
def get_remote_address(self) -> tuple[str, int] | None:
|
||||||
"""Delegate to the underlying muxed stream."""
|
"""Delegate to the underlying muxed stream."""
|
||||||
return self.muxed_stream.get_remote_address()
|
return self.muxed_stream.get_remote_address()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user