Skip to content

Commit d8d6a2d

Browse files
committed
Run pre-commit on all files and fix issues
1 parent 0eaaaa3 commit d8d6a2d

39 files changed

+184
-88
lines changed

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ help:
1717
# Catch-all target: route all unknown targets to Sphinx using the new
1818
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1919
%: Makefile
20-
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/source/local_customization.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from docutils.parsers.rst import directives
1+
from docutils.parsers.rst import directives as directives # noqa: F401
22
from sphinx import addnodes
33
from sphinx.domains.python import PyClasslike
4-
from sphinx.ext.autodoc import (
5-
FunctionDocumenter,
6-
MethodDocumenter,
7-
ClassLevelDocumenter,
8-
Options,
4+
from sphinx.ext.autodoc import ( # noqa: F401
5+
ClassLevelDocumenter as ClassLevelDocumenter,
6+
FunctionDocumenter as FunctionDocumenter,
7+
MethodDocumenter as MethodDocumenter,
8+
Options as Options,
99
)
1010

1111
"""

docs/source/reference-core/channels-backpressure.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Simulate a producer that generates values 10x faster than the
22
# consumer can handle them.
33

4-
import trio
54
import math
65

6+
import trio
7+
78

89
async def producer(send_channel):
910
count = 0

docs/source/reference-core/channels-mpmc-broken.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# This example usually crashes!
22

3-
import trio
43
import random
54

5+
import trio
6+
67

78
async def main():
89
async with trio.open_nursery() as nursery:

docs/source/reference-core/channels-mpmc-fixed.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import trio
21
import random
32

3+
import trio
4+
45

56
async def main():
67
async with trio.open_nursery() as nursery:

docs/source/reference-core/contextvar-example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import contextvars
12
import random
3+
24
import trio
3-
import contextvars
45

56
request_info = contextvars.ContextVar("request_info")
67

docs/source/reference-core/thread-contextvars-example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
request_state = contextvars.ContextVar("request_state")
77

8+
89
# Blocking function that should be run on a thread
910
# It could be reading or writing files, communicating with a database
1011
# with a driver not compatible with async / await, etc.

docs/source/reference-testing/across-realtime.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# across-realtime.py
22

33
import time
4+
45
import trio
56
import trio.testing
67

docs/source/tutorial/echo-client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# echo-client.py
22

33
import sys
4+
45
import trio
56

67
# arbitrary, but:

docs/source/tutorial/echo-server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# echo-server.py
22

3-
import trio
43
from itertools import count
54

5+
import trio
6+
67
# Port is arbitrary, but:
78
# - must be in between 1024 and 65535
89
# - can't be in use by some other program on your computer

notes-to-self/afd-lab.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,27 @@
7777
# matter, energy, and life which lie close at hand yet can never be detected
7878
# with the senses we have."
7979

80-
import sys
8180
import os.path
81+
import sys
82+
8283
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + r"\.."))
8384

8485
import trio
86+
8587
print(trio.__file__)
86-
import trio.testing
8788
import socket
8889

90+
import trio.testing
91+
from trio._core._io_windows import _afd_helper_handle, _check, _get_base_socket
8992
from trio._core._windows_cffi import (
90-
ffi, kernel32, AFDPollFlags, IoControlCodes, ErrorCodes
91-
)
92-
from trio._core._io_windows import (
93-
_get_base_socket, _afd_helper_handle, _check
93+
AFDPollFlags,
94+
ErrorCodes,
95+
IoControlCodes,
96+
ffi,
97+
kernel32,
9498
)
9599

100+
96101
class AFDLab:
97102
def __init__(self):
98103
self._afd = _afd_helper_handle()
@@ -173,4 +178,5 @@ async def main():
173178
await trio.sleep(2)
174179
nursery.cancel_scope.cancel()
175180

181+
176182
trio.run(main)

notes-to-self/aio-guest-test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import asyncio
2+
23
import trio
34

5+
46
async def aio_main():
57
loop = asyncio.get_running_loop()
68

79
trio_done_fut = loop.create_future()
10+
811
def trio_done_callback(main_outcome):
912
print(f"trio_main finished: {main_outcome!r}")
1013
trio_done_fut.set_result(main_outcome)
@@ -35,6 +38,7 @@ async def trio_main():
3538
if n >= 10:
3639
return
3740

41+
3842
async def aio_pingpong(from_trio, to_trio):
3943
print("aio_pingpong!")
4044

notes-to-self/atomic-local.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
# Has to be a string :-(
44
sentinel = "_unique_name"
55

6+
67
def f():
78
print(locals())
89

10+
911
# code(argcount, kwonlyargcount, nlocals, stacksize, flags, codestring,
1012
# constants, names, varnames, filename, name, firstlineno,
1113
# lnotab[, freevars[, cellvars]])

notes-to-self/blocking-read-hack.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import trio
1+
import errno
22
import os
33
import socket
4-
import errno
4+
5+
import trio
56

67
bad_socket = socket.socket()
78

9+
810
class BlockingReadTimeoutError(Exception):
911
pass
1012

13+
1114
async def blocking_read_with_timeout(fd, count, timeout):
1215
print("reading from fd", fd)
1316
cancel_requested = False
@@ -42,4 +45,5 @@ async def kill_it_after_timeout(new_fd):
4245
finally:
4346
os.close(new_fd)
4447

48+
4549
trio.run(blocking_read_with_timeout, 0, 10, 2)

notes-to-self/estimate-task-size.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
# Little script to get a rough estimate of how much memory each task takes
22

33
import resource
4+
45
import trio
56
import trio.testing
67

78
LOW = 1000
89
HIGH = 10000
910

11+
1012
async def tinytask():
1113
await trio.sleep_forever()
1214

15+
1316
async def measure(count):
1417
async with trio.open_nursery() as nursery:
1518
for _ in range(count):
@@ -23,8 +26,8 @@ async def main():
2326
low_usage = await measure(LOW)
2427
high_usage = await measure(HIGH + LOW)
2528

26-
print("Memory usage per task:",
27-
(high_usage.ru_maxrss - low_usage.ru_maxrss) / HIGH)
29+
print("Memory usage per task:", (high_usage.ru_maxrss - low_usage.ru_maxrss) / HIGH)
2830
print("(kilobytes on Linux, bytes on macOS)")
2931

32+
3033
trio.run(main)

notes-to-self/fbsd-pipe-close-notify.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
#
55
# Upstream bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=246350
66

7-
import select
87
import os
9-
import threading
8+
import select
109

1110
r, w = os.pipe()
1211

notes-to-self/file-read-latency.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# ns per call, instead of ~500 ns/call for the syscall and related overhead.
99
# That's probably more fair -- the BufferedIOBase code can't service random
1010
# accesses, even if your working set fits entirely in RAM.
11-
f = open("/etc/passwd", "rb")#, buffering=0)
11+
f = open("/etc/passwd", "rb") # , buffering=0)
1212

1313
while True:
1414
start = time.perf_counter()
@@ -23,5 +23,8 @@
2323
both = (between - start) / COUNT * 1e9
2424
seek = (end - between) / COUNT * 1e9
2525
read = both - seek
26-
print("{:.2f} ns/(seek+read), {:.2f} ns/seek, estimate ~{:.2f} ns/read"
27-
.format(both, seek, read))
26+
print(
27+
"{:.2f} ns/(seek+read), {:.2f} ns/seek, estimate ~{:.2f} ns/read".format(
28+
both, seek, read
29+
)
30+
)

notes-to-self/graceful-shutdown-idea.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import trio
22

3+
34
class GracefulShutdownManager:
45
def __init__(self):
56
self._shutting_down = False
@@ -21,6 +22,7 @@ def cancel_on_graceful_shutdown(self):
2122
def shutting_down(self):
2223
return self._shutting_down
2324

25+
2426
# Code can check gsm.shutting_down occasionally at appropriate points to see
2527
# if it should exit.
2628
#
@@ -31,9 +33,11 @@ async def stream_handler(stream):
3133
while True:
3234
with gsm.cancel_on_graceful_shutdown():
3335
data = await stream.receive_some()
36+
print(f"{data = }")
3437
if gsm.shutting_down:
3538
break
3639

40+
3741
# To trigger the shutdown:
3842
async def listen_for_shutdown_signals():
3943
with trio.open_signal_receiver(signal.SIGINT, signal.SIGTERM) as signal_aiter:

notes-to-self/how-does-windows-so-reuseaddr-work.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#
55
# See https://github.com/python-trio/trio/issues/928 for details and context
66

7-
import socket
87
import errno
8+
import socket
99

1010
modes = ["default", "SO_REUSEADDR", "SO_EXCLUSIVEADDRUSE"]
1111
bind_types = ["wildcard", "specific"]

notes-to-self/loopy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import trio
21
import time
32

3+
import trio
4+
5+
46
async def loopy():
57
try:
68
while True:
@@ -9,10 +11,12 @@ async def loopy():
911
except KeyboardInterrupt:
1012
print("KI!")
1113

14+
1215
async def main():
1316
async with trio.open_nursery() as nursery:
1417
nursery.start_soon(loopy)
1518
nursery.start_soon(loopy)
1619
nursery.start_soon(loopy)
1720

21+
1822
trio.run(main)

notes-to-self/lots-of-tasks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import sys
2+
23
import trio
34

45
(COUNT_STR,) = sys.argv[1:]
56
COUNT = int(COUNT_STR)
67

8+
79
async def main():
810
async with trio.open_nursery() as nursery:
911
for _ in range(COUNT):
1012
nursery.start_soon(trio.sleep, 1)
1113

14+
1215
trio.run(main)

notes-to-self/manual-signal-handler.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33

44
if os.name == "nt":
55
import cffi
6+
67
ffi = cffi.FFI()
7-
ffi.cdef("""
8+
ffi.cdef(
9+
"""
810
void* WINAPI GetProcAddress(void* hModule, char* lpProcName);
911
typedef void (*PyOS_sighandler_t)(int);
10-
""")
12+
"""
13+
)
1114
kernel32 = ffi.dlopen("kernel32.dll")
1215
PyOS_getsig_ptr = kernel32.GetProcAddress(
13-
ffi.cast("void*", sys.dllhandle), b"PyOS_getsig")
16+
ffi.cast("void*", sys.dllhandle), b"PyOS_getsig"
17+
)
1418
PyOS_getsig = ffi.cast("PyOS_sighandler_t (*)(int)", PyOS_getsig_ptr)
1519

16-
1720
import signal
21+
1822
PyOS_getsig(signal.SIGINT)(signal.SIGINT)

notes-to-self/measure-listen-backlog.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import trio
22

3+
34
async def run_test(nominal_backlog):
45
print("--\nnominal:", nominal_backlog)
56

@@ -22,5 +23,6 @@ async def run_test(nominal_backlog):
2223
for client_sock in client_socks:
2324
client_sock.close()
2425

26+
2527
for nominal_backlog in [10, trio.socket.SOMAXCONN, 65535]:
2628
trio.run(run_test, nominal_backlog)

0 commit comments

Comments
 (0)