run lint with pyupgrade at py39-plus

This commit is contained in:
pacrob
2025-01-25 15:31:51 -07:00
committed by Paul Robinson
parent 20580b9a4e
commit 8787613e91
44 changed files with 221 additions and 240 deletions

View File

@ -1,9 +1,6 @@
from abc import (
abstractmethod,
)
from typing import (
Tuple,
)
import trio
@ -27,5 +24,5 @@ class INetConn(Closer):
...
@abstractmethod
def get_streams(self) -> Tuple[INetStream, ...]:
def get_streams(self) -> tuple[INetStream, ...]:
...

View File

@ -1,7 +1,5 @@
from typing import (
TYPE_CHECKING,
Set,
Tuple,
)
import trio
@ -32,7 +30,7 @@ Reference: https://github.com/libp2p/go-libp2p-swarm/blob/04c86bbdafd390651cb2ee
class SwarmConn(INetConn):
muxed_conn: IMuxedConn
swarm: "Swarm"
streams: Set[NetStream]
streams: set[NetStream]
event_closed: trio.Event
def __init__(self, muxed_conn: IMuxedConn, swarm: "Swarm") -> None:
@ -104,7 +102,7 @@ class SwarmConn(INetConn):
muxed_stream = await self.muxed_conn.open_stream()
return await self._add_stream(muxed_stream)
def get_streams(self) -> Tuple[NetStream, ...]:
def get_streams(self) -> tuple[NetStream, ...]:
return tuple(self.streams)
def remove_stream(self, stream: NetStream) -> None:

View File

@ -2,10 +2,11 @@ from abc import (
ABC,
abstractmethod,
)
from collections.abc import (
Sequence,
)
from typing import (
TYPE_CHECKING,
Dict,
Sequence,
)
from multiaddr import (
@ -41,8 +42,8 @@ if TYPE_CHECKING:
class INetwork(ABC):
peerstore: IPeerStore
connections: Dict[ID, INetConn]
listeners: Dict[str, IListener]
connections: dict[ID, INetConn]
listeners: dict[str, IListener]
@abstractmethod
def get_peer_id(self) -> ID:

View File

@ -1,7 +1,5 @@
import logging
from typing import (
Dict,
List,
Optional,
)
@ -88,13 +86,13 @@ class Swarm(Service, INetworkService):
transport: ITransport
# TODO: Connection and `peer_id` are 1-1 mapping in our implementation,
# whereas in Go one `peer_id` may point to multiple connections.
connections: Dict[ID, INetConn]
listeners: Dict[str, IListener]
connections: dict[ID, INetConn]
listeners: dict[str, IListener]
common_stream_handler: StreamHandlerFn
listener_nursery: Optional[trio.Nursery]
event_listener_nursery_created: trio.Event
notifees: List[INotifee]
notifees: list[INotifee]
def __init__(
self,
@ -161,7 +159,7 @@ class Swarm(Service, INetworkService):
if not addrs:
raise SwarmException(f"No known addresses to peer {peer_id}")
exceptions: List[SwarmException] = []
exceptions: list[SwarmException] = []
# Try all known addresses
for multiaddr in addrs: