From 94c709d99893f6c2e73618d6cdbe169ddb37871a Mon Sep 17 00:00:00 2001 From: "Nathaniel J. Smith" Date: Thu, 27 Sep 2018 17:34:20 -0700 Subject: [PATCH 1/3] Bump yapf to 0.24, and re-run with new version I'm also curious how the update bots will handle this. --- .style.yapf | 5 +++++ test-requirements.in | 2 +- trio/_core/_io_windows.py | 4 ++-- trio/_core/_run.py | 13 +++++++------ trio/_socket.py | 5 +++-- trio/_sync.py | 15 +++++++++------ trio/testing/_mock_clock.py | 5 +++-- trio/tests/test_highlevel_serve_listeners.py | 3 ++- trio/tests/test_sync.py | 3 ++- trio/tests/test_testing.py | 5 +++-- 10 files changed, 37 insertions(+), 23 deletions(-) diff --git a/.style.yapf b/.style.yapf index 2c5517ec40..745ec88d70 100644 --- a/.style.yapf +++ b/.style.yapf @@ -178,3 +178,8 @@ split_penalty_logical_operator=0 # Use the Tab character for indentation. use_tabs=False +# Without this, yapf likes to write things like +# "foo bar {}". +# format(...) +# which is just awful. +split_before_dot=True diff --git a/test-requirements.in b/test-requirements.in index 5d63d3dc83..9f28aec952 100644 --- a/test-requirements.in +++ b/test-requirements.in @@ -9,7 +9,7 @@ pylint # for pylint finding all symbols tests jedi # for jedi code completion tests # Tools -yapf == 0.22.0 # formatting; also pinned in renovate.json +yapf == 0.24.0 # formatting flake8 # https://github.com/python-trio/trio/pull/654#issuecomment-420518745 diff --git a/trio/_core/_io_windows.py b/trio/_core/_io_windows.py index d044b1f0a5..73d7cc9409 100644 --- a/trio/_core/_io_windows.py +++ b/trio/_core/_io_windows.py @@ -341,8 +341,8 @@ async def _wait_socket(self, which, sock): if sock in self._socket_waiters[which]: await _core.checkpoint() raise _core.ResourceBusyError( - "another task is already waiting to {} this socket" - .format(which) + "another task is already waiting to {} this socket". + format(which) ) self._socket_waiters[which][sock] = _core.current_task() diff --git a/trio/_core/_run.py b/trio/_core/_run.py index 644133bf7d..f872678933 100644 --- a/trio/_core/_run.py +++ b/trio/_core/_run.py @@ -858,8 +858,8 @@ def _return_value_looks_like_wrong_library(value): "trio was expecting an async function, but instead it got " "{!r} – are you trying to use a library written for " "asyncio/twisted/tornado or similar? That won't work " - "without some sort of compatibility shim." - .format(async_fn) + "without some sort of compatibility shim.". + format(async_fn) ) from None raise @@ -874,8 +874,8 @@ def _return_value_looks_like_wrong_library(value): raise TypeError( "start_soon got unexpected {!r} – are you trying to use a " "library written for asyncio/twisted/tornado or similar? " - "That won't work without some sort of compatibility shim." - .format(coro) + "That won't work without some sort of compatibility shim.". + format(coro) ) if isasyncgen(coro): @@ -887,8 +887,9 @@ def _return_value_looks_like_wrong_library(value): # Give good error for: nursery.start_soon(some_sync_fn) raise TypeError( "trio expected an async function, but {!r} appears to be " - "synchronous" - .format(getattr(async_fn, "__qualname__", async_fn)) + "synchronous".format( + getattr(async_fn, "__qualname__", async_fn) + ) ) ###### diff --git a/trio/_socket.py b/trio/_socket.py index 133b32c2b9..507c4b07a6 100644 --- a/trio/_socket.py +++ b/trio/_socket.py @@ -389,8 +389,9 @@ def __init__(self, sock): # For example, ssl.SSLSocket subclasses socket.socket, but we # certainly don't want to blindly wrap one of those. raise TypeError( - "expected object of type 'socket.socket', not '{}" - .format(type(sock).__name__) + "expected object of type 'socket.socket', not '{}".format( + type(sock).__name__ + ) ) self._sock = sock self._sock.setblocking(False) diff --git a/trio/_sync.py b/trio/_sync.py index 51b095f671..f9a22b49d9 100644 --- a/trio/_sync.py +++ b/trio/_sync.py @@ -415,8 +415,9 @@ def __repr__(self): else: max_value_str = ", max_value={}".format(self._max_value) return ( - "" - .format(self._value, max_value_str, id(self)) + "".format( + self._value, max_value_str, id(self) + ) ) @property @@ -524,8 +525,9 @@ def __repr__(self): s1 = "unlocked" s2 = "" return ( - "<{} {} object at {:#x}{}>" - .format(s1, self.__class__.__name__, id(self), s2) + "<{} {} object at {:#x}{}>".format( + s1, self.__class__.__name__, id(self), s2 + ) ) def locked(self): @@ -858,8 +860,9 @@ def __init__(self, capacity): def __repr__(self): return ( - "" - .format(self.capacity, id(self), len(self._data)) + "".format( + self.capacity, id(self), len(self._data) + ) ) def qsize(self): diff --git a/trio/testing/_mock_clock.py b/trio/testing/_mock_clock.py index a013e4da79..09d3ea7091 100644 --- a/trio/testing/_mock_clock.py +++ b/trio/testing/_mock_clock.py @@ -100,8 +100,9 @@ def __init__(self, rate=0.0, autojump_threshold=inf): def __repr__(self): return ( - "" - .format(self.current_time(), self._rate, id(self)) + "".format( + self.current_time(), self._rate, id(self) + ) ) @property diff --git a/trio/tests/test_highlevel_serve_listeners.py b/trio/tests/test_highlevel_serve_listeners.py index c72f350618..7d237419a6 100644 --- a/trio/tests/test_highlevel_serve_listeners.py +++ b/trio/tests/test_highlevel_serve_listeners.py @@ -137,7 +137,8 @@ async def connection_watcher(*, task_status=trio.TASK_STATUS_IGNORED): await nursery.start( partial( trio.serve_listeners, - handler, [listener], + handler, + [listener], handler_nursery=handler_nursery ) ) diff --git a/trio/tests/test_sync.py b/trio/tests/test_sync.py index c6842ca2f8..c30992804f 100644 --- a/trio/tests/test_sync.py +++ b/trio/tests/test_sync.py @@ -228,7 +228,8 @@ async def test_Semaphore_bounded(): @pytest.mark.parametrize( - "lockcls", [Lock, StrictFIFOLock], ids=lambda fn: fn.__name__ + "lockcls", + [Lock, StrictFIFOLock], ids=lambda fn: fn.__name__ ) async def test_Lock_and_StrictFIFOLock(lockcls): l = lockcls() # noqa diff --git a/trio/tests/test_testing.py b/trio/tests/test_testing.py index 8abf8eb5ff..a7df5275d7 100644 --- a/trio/tests/test_testing.py +++ b/trio/tests/test_testing.py @@ -322,8 +322,9 @@ async def test_mock_clock_autojump(mock_clock): real_duration = time.monotonic() - real_start print( - "Slept {} seconds in {} seconds" - .format(10 * sum(range(10)), real_duration) + "Slept {} seconds in {} seconds".format( + 10 * sum(range(10)), real_duration + ) ) assert real_duration < 1 From be417ea1928a077ac0fe61e020efb3df6d7b9ae3 Mon Sep 17 00:00:00 2001 From: "Nathaniel J. Smith" Date: Thu, 27 Sep 2018 18:37:54 -0700 Subject: [PATCH 2/3] Update test-requirements.txt too, duh --- test-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-requirements.txt b/test-requirements.txt index 9d226523c1..e2b1924a4b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -47,4 +47,4 @@ trustme==0.4.0 typed-ast==1.1.0 ; python_version < "3.7" and implementation_name == "cpython" wcwidth==0.1.7 # via prompt-toolkit wrapt==1.10.11 # via astroid -yapf==0.22.0 +yapf==0.24.0 From 5f522fc983ebbb51f1ed2e6cd852a63fb07b31a3 Mon Sep 17 00:00:00 2001 From: "Nathaniel J. Smith" Date: Thu, 27 Sep 2018 18:42:47 -0700 Subject: [PATCH 3/3] Run yapf *again*, because I guess the first time didn't take? Maybe it's and needs multiple runs now to converge? ughhh --- trio/_core/_io_windows.py | 4 ++-- trio/_core/_run.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/trio/_core/_io_windows.py b/trio/_core/_io_windows.py index 73d7cc9409..d044b1f0a5 100644 --- a/trio/_core/_io_windows.py +++ b/trio/_core/_io_windows.py @@ -341,8 +341,8 @@ async def _wait_socket(self, which, sock): if sock in self._socket_waiters[which]: await _core.checkpoint() raise _core.ResourceBusyError( - "another task is already waiting to {} this socket". - format(which) + "another task is already waiting to {} this socket" + .format(which) ) self._socket_waiters[which][sock] = _core.current_task() diff --git a/trio/_core/_run.py b/trio/_core/_run.py index f872678933..265068f96c 100644 --- a/trio/_core/_run.py +++ b/trio/_core/_run.py @@ -858,8 +858,8 @@ def _return_value_looks_like_wrong_library(value): "trio was expecting an async function, but instead it got " "{!r} – are you trying to use a library written for " "asyncio/twisted/tornado or similar? That won't work " - "without some sort of compatibility shim.". - format(async_fn) + "without some sort of compatibility shim." + .format(async_fn) ) from None raise @@ -874,8 +874,8 @@ def _return_value_looks_like_wrong_library(value): raise TypeError( "start_soon got unexpected {!r} – are you trying to use a " "library written for asyncio/twisted/tornado or similar? " - "That won't work without some sort of compatibility shim.". - format(coro) + "That won't work without some sort of compatibility shim." + .format(coro) ) if isasyncgen(coro):