run lint and fix errors, except mypy

This commit is contained in:
pacrob
2024-02-19 15:56:20 -07:00
parent 42605c0288
commit 94483714a3
171 changed files with 4809 additions and 2290 deletions

View File

@ -1,4 +1,6 @@
from libp2p.io.exceptions import IOException
from libp2p.io.exceptions import (
IOException,
)
class RawConnError(IOException):

View File

@ -1,11 +1,21 @@
from abc import abstractmethod
from typing import Tuple
from abc import (
abstractmethod,
)
from typing import (
Tuple,
)
import trio
from libp2p.io.abc import Closer
from libp2p.network.stream.net_stream_interface import INetStream
from libp2p.stream_muxer.abc import IMuxedConn
from libp2p.io.abc import (
Closer,
)
from libp2p.network.stream.net_stream_interface import (
INetStream,
)
from libp2p.stream_muxer.abc import (
IMuxedConn,
)
class INetConn(Closer):

View File

@ -1,8 +1,16 @@
from libp2p.io.abc import ReadWriteCloser
from libp2p.io.exceptions import IOException
from libp2p.io.abc import (
ReadWriteCloser,
)
from libp2p.io.exceptions import (
IOException,
)
from .exceptions import RawConnError
from .raw_connection_interface import IRawConnection
from .exceptions import (
RawConnError,
)
from .raw_connection_interface import (
IRawConnection,
)
class RawConnection(IRawConnection):

View File

@ -1,4 +1,6 @@
from libp2p.io.abc import ReadWriteCloser
from libp2p.io.abc import (
ReadWriteCloser,
)
class IRawConnection(ReadWriteCloser):

View File

@ -1,11 +1,24 @@
from typing import TYPE_CHECKING, Set, Tuple
from typing import (
TYPE_CHECKING,
Set,
Tuple,
)
import trio
from libp2p.network.connection.net_connection_interface import INetConn
from libp2p.network.stream.net_stream import NetStream
from libp2p.stream_muxer.abc import IMuxedConn, IMuxedStream
from libp2p.stream_muxer.exceptions import MuxedConnUnavailable
from libp2p.network.connection.net_connection_interface import (
INetConn,
)
from libp2p.network.stream.net_stream import (
NetStream,
)
from libp2p.stream_muxer.abc import (
IMuxedConn,
IMuxedStream,
)
from libp2p.stream_muxer.exceptions import (
MuxedConnUnavailable,
)
if TYPE_CHECKING:
from libp2p.network.swarm import Swarm # noqa: F401
@ -48,8 +61,8 @@ class SwarmConn(INetConn):
# We *could* optimize this but it really isn't worth it.
for stream in self.streams.copy():
await stream.reset()
# Force context switch for stream handlers to process the stream reset event we just emit
# before we cancel the stream handler tasks.
# Force context switch for stream handlers to process the stream reset event we
# just emit before we cancel the stream handler tasks.
await trio.sleep(0.1)
await self._notify_disconnected()
@ -63,13 +76,15 @@ class SwarmConn(INetConn):
except MuxedConnUnavailable:
await self.close()
break
# Asynchronously handle the accepted stream, to avoid blocking the next stream.
# Asynchronously handle the accepted stream, to avoid blocking
# the next stream.
nursery.start_soon(self._handle_muxed_stream, stream)
async def _handle_muxed_stream(self, muxed_stream: IMuxedStream) -> None:
net_stream = await self._add_stream(muxed_stream)
try:
# Ignore type here since mypy complains: https://github.com/python/mypy/issues/2427
# Ignore type here since mypy complains:
# https://github.com/python/mypy/issues/2427
await self.swarm.common_stream_handler(net_stream) # type: ignore
finally:
# As long as `common_stream_handler`, remove the stream.