mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-32262: Fix codestyle; use f-strings formatting where necessary. (#4775)
This commit is contained in:
parent
c4d9df5fd7
commit
6370f345e1
24 changed files with 332 additions and 348 deletions
|
@ -4,7 +4,7 @@ A selector is a "notify-when-ready" multiplexer. For a subclass which
|
|||
also includes support for signal handling, see the unix_events sub-module.
|
||||
"""
|
||||
|
||||
__all__ = ['BaseSelectorEventLoop']
|
||||
__all__ = 'BaseSelectorEventLoop',
|
||||
|
||||
import collections
|
||||
import errno
|
||||
|
@ -184,8 +184,8 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
|
|||
raise # The event loop will catch, log and ignore it.
|
||||
else:
|
||||
extra = {'peername': addr}
|
||||
accept = self._accept_connection2(protocol_factory, conn, extra,
|
||||
sslcontext, server)
|
||||
accept = self._accept_connection2(
|
||||
protocol_factory, conn, extra, sslcontext, server)
|
||||
self.create_task(accept)
|
||||
|
||||
async def _accept_connection2(self, protocol_factory, conn, extra,
|
||||
|
@ -214,8 +214,8 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
|
|||
except Exception as exc:
|
||||
if self._debug:
|
||||
context = {
|
||||
'message': ('Error on transport creation '
|
||||
'for incoming connection'),
|
||||
'message':
|
||||
'Error on transport creation for incoming connection',
|
||||
'exception': exc,
|
||||
}
|
||||
if protocol is not None:
|
||||
|
@ -231,8 +231,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
|
|||
fileno = int(fileno.fileno())
|
||||
except (AttributeError, TypeError, ValueError):
|
||||
# This code matches selectors._fileobj_to_fd function.
|
||||
raise ValueError("Invalid file object: "
|
||||
"{!r}".format(fd)) from None
|
||||
raise ValueError(f"Invalid file object: {fd!r}") from None
|
||||
try:
|
||||
transport = self._transports[fileno]
|
||||
except KeyError:
|
||||
|
@ -240,8 +239,8 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
|
|||
else:
|
||||
if not transport.is_closing():
|
||||
raise RuntimeError(
|
||||
'File descriptor {!r} is used by transport {!r}'.format(
|
||||
fd, transport))
|
||||
f'File descriptor {fd!r} is used by transport '
|
||||
f'{transport!r}')
|
||||
|
||||
def _add_reader(self, fd, callback, *args):
|
||||
self._check_closed()
|
||||
|
@ -389,10 +388,11 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
|
|||
|
||||
def _sock_recv_into(self, fut, registered_fd, sock, buf):
|
||||
# _sock_recv_into() can add itself as an I/O callback if the operation
|
||||
# can't be done immediately. Don't use it directly, call sock_recv_into().
|
||||
# can't be done immediately. Don't use it directly, call
|
||||
# sock_recv_into().
|
||||
if registered_fd is not None:
|
||||
# Remove the callback early. It should be rare that the
|
||||
# selector says the fd is ready but the call still returns
|
||||
# selector says the FD is ready but the call still returns
|
||||
# EAGAIN, and I am willing to take a hit in that case in
|
||||
# order to simplify the common case.
|
||||
self.remove_reader(registered_fd)
|
||||
|
@ -497,7 +497,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
|
|||
err = sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
|
||||
if err != 0:
|
||||
# Jump to any except clause below.
|
||||
raise OSError(err, 'Connect call failed %s' % (address,))
|
||||
raise OSError(err, f'Connect call failed {address}')
|
||||
except (BlockingIOError, InterruptedError):
|
||||
# socket is still registered, the callback will be retried later
|
||||
pass
|
||||
|
@ -596,7 +596,7 @@ class _SelectorTransport(transports._FlowControlMixin,
|
|||
info.append('closed')
|
||||
elif self._closing:
|
||||
info.append('closing')
|
||||
info.append('fd=%s' % self._sock_fd)
|
||||
info.append(f'fd={self._sock_fd}')
|
||||
# test if the transport was closed
|
||||
if self._loop is not None and not self._loop.is_closed():
|
||||
polling = _test_selector_event(self._loop._selector,
|
||||
|
@ -615,8 +615,8 @@ class _SelectorTransport(transports._FlowControlMixin,
|
|||
state = 'idle'
|
||||
|
||||
bufsize = self.get_write_buffer_size()
|
||||
info.append('write=<%s, bufsize=%s>' % (state, bufsize))
|
||||
return '<%s>' % ' '.join(info)
|
||||
info.append(f'write=<{state}, bufsize={bufsize}>')
|
||||
return '<{}>'.format(' '.join(info))
|
||||
|
||||
def abort(self):
|
||||
self._force_close(None)
|
||||
|
@ -642,7 +642,7 @@ class _SelectorTransport(transports._FlowControlMixin,
|
|||
|
||||
def __del__(self):
|
||||
if self._sock is not None:
|
||||
warnings.warn("unclosed transport %r" % self, ResourceWarning,
|
||||
warnings.warn(f"unclosed transport {self!r}", ResourceWarning,
|
||||
source=self)
|
||||
self._sock.close()
|
||||
|
||||
|
@ -758,8 +758,8 @@ class _SelectorSocketTransport(_SelectorTransport):
|
|||
|
||||
def write(self, data):
|
||||
if not isinstance(data, (bytes, bytearray, memoryview)):
|
||||
raise TypeError('data argument must be a bytes-like object, '
|
||||
'not %r' % type(data).__name__)
|
||||
raise TypeError(f'data argument must be a bytes-like object, '
|
||||
f'not {type(data).__name__!r}')
|
||||
if self._eof:
|
||||
raise RuntimeError('Cannot call write() after write_eof()')
|
||||
if not data:
|
||||
|
@ -862,14 +862,14 @@ class _SelectorDatagramTransport(_SelectorTransport):
|
|||
|
||||
def sendto(self, data, addr=None):
|
||||
if not isinstance(data, (bytes, bytearray, memoryview)):
|
||||
raise TypeError('data argument must be a bytes-like object, '
|
||||
'not %r' % type(data).__name__)
|
||||
raise TypeError(f'data argument must be a bytes-like object, '
|
||||
f'not {type(data).__name__!r}')
|
||||
if not data:
|
||||
return
|
||||
|
||||
if self._address and addr not in (None, self._address):
|
||||
raise ValueError('Invalid address: must be None or %s' %
|
||||
(self._address,))
|
||||
raise ValueError(
|
||||
f'Invalid address: must be None or {self._address}')
|
||||
|
||||
if self._conn_lost and self._address:
|
||||
if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
|
||||
|
@ -891,8 +891,8 @@ class _SelectorDatagramTransport(_SelectorTransport):
|
|||
self._protocol.error_received(exc)
|
||||
return
|
||||
except Exception as exc:
|
||||
self._fatal_error(exc,
|
||||
'Fatal write error on datagram transport')
|
||||
self._fatal_error(
|
||||
exc, 'Fatal write error on datagram transport')
|
||||
return
|
||||
|
||||
# Ensure that what we buffer is immutable.
|
||||
|
@ -914,8 +914,8 @@ class _SelectorDatagramTransport(_SelectorTransport):
|
|||
self._protocol.error_received(exc)
|
||||
return
|
||||
except Exception as exc:
|
||||
self._fatal_error(exc,
|
||||
'Fatal write error on datagram transport')
|
||||
self._fatal_error(
|
||||
exc, 'Fatal write error on datagram transport')
|
||||
return
|
||||
|
||||
self._maybe_resume_protocol() # May append to buffer.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue