mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-09 14:40:53 +00:00
Replace (check and) del pattern with pop method
This commit is contained in:
@ -297,8 +297,7 @@ class Mplex(IMuxedConn):
|
||||
# the entry of this stream, to avoid others from accessing it.
|
||||
if is_local_closed:
|
||||
async with self.streams_lock:
|
||||
if stream_id in self.streams:
|
||||
del self.streams[stream_id]
|
||||
self.streams.pop(stream_id, None)
|
||||
|
||||
async def _handle_reset(self, stream_id: StreamID) -> None:
|
||||
async with self.streams_lock:
|
||||
@ -316,8 +315,7 @@ class Mplex(IMuxedConn):
|
||||
if not stream.event_local_closed.is_set():
|
||||
stream.event_local_closed.set()
|
||||
async with self.streams_lock:
|
||||
if stream_id in self.streams:
|
||||
del self.streams[stream_id]
|
||||
self.streams.pop(stream_id, None)
|
||||
|
||||
async def _cleanup(self) -> None:
|
||||
if not self.event_shutting_down.is_set():
|
||||
|
||||
@ -180,8 +180,7 @@ class MplexStream(IMuxedStream):
|
||||
if _is_remote_closed:
|
||||
# Both sides are closed, we can safely remove the buffer from the dict.
|
||||
async with self.muxed_conn.streams_lock:
|
||||
if self.stream_id in self.muxed_conn.streams:
|
||||
del self.muxed_conn.streams[self.stream_id]
|
||||
self.muxed_conn.streams.pop(self.stream_id, None)
|
||||
|
||||
async def reset(self) -> None:
|
||||
"""closes both ends of the stream tells this remote side to hang up."""
|
||||
@ -208,11 +207,8 @@ class MplexStream(IMuxedStream):
|
||||
self.event_remote_closed.set()
|
||||
|
||||
async with self.muxed_conn.streams_lock:
|
||||
if (
|
||||
self.muxed_conn.streams is not None
|
||||
and self.stream_id in self.muxed_conn.streams
|
||||
):
|
||||
del self.muxed_conn.streams[self.stream_id]
|
||||
if self.muxed_conn.streams is not None:
|
||||
self.muxed_conn.streams.pop(self.stream_id, None)
|
||||
|
||||
# TODO deadline not in use
|
||||
def set_deadline(self, ttl: int) -> bool:
|
||||
|
||||
@ -44,8 +44,7 @@ class MuxerMultistream:
|
||||
:param transport: the corresponding transportation to the ``protocol``.
|
||||
"""
|
||||
# If protocol is already added before, remove it and add it again.
|
||||
if protocol in self.transports:
|
||||
del self.transports[protocol]
|
||||
self.transports.pop(protocol, None)
|
||||
self.transports[protocol] = transport
|
||||
self.multiselect.add_handler(protocol, None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user