Skip to content

Commit

Permalink
Merge branch 'master' into enable-flake8-simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCat467 authored Oct 23, 2023
2 parents 94d11a2 + 01638f8 commit e55b1e3
Show file tree
Hide file tree
Showing 58 changed files with 314 additions and 211 deletions.
8 changes: 4 additions & 4 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ attrs==23.1.0
# via
# -r docs-requirements.in
# outcome
babel==2.12.1
babel==2.13.0
# via sphinx
certifi==2023.7.22
# via requests
Expand Down Expand Up @@ -53,9 +53,9 @@ jinja2==3.1.2
# towncrier
markupsafe==2.1.3
# via jinja2
outcome==1.2.0
outcome==1.3.0
# via -r docs-requirements.in
packaging==23.1
packaging==23.2
# via sphinx
pycparser==2.21
# via cffi
Expand Down Expand Up @@ -103,7 +103,7 @@ tomli==2.0.1
# via towncrier
towncrier==23.6.0
# via -r docs-requirements.in
urllib3==2.0.5
urllib3==2.0.7
# via requests
zipp==3.17.0
# via
Expand Down
4 changes: 0 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@
# aliasing doesn't actually fix the warning for types.FrameType, but displaying
# "types.FrameType" is more helpful than just "frame"
"FrameType": "types.FrameType",
# unaliasing these makes intersphinx able to resolve them
"Outcome": "outcome.Outcome",
"Context": "OpenSSL.SSL.Context",
}

Expand All @@ -82,8 +80,6 @@ def autodoc_process_signature(
"""Modify found signatures to fix various issues."""
if signature is not None:
signature = signature.replace("~_contextvars.Context", "~contextvars.Context")
if name == "trio.lowlevel.start_guest_run":
signature = signature.replace("Outcome", "~outcome.Outcome")
if name == "trio.lowlevel.RunVar": # Typevar is not useful here.
signature = signature.replace(": ~trio._core._local.T", "")
if "_NoValue" in signature:
Expand Down
7 changes: 7 additions & 0 deletions newsfragments/1457.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
When exiting a nursery block, the parent task always waits for child
tasks to exit. This wait cannot be cancelled. However, previously, if
you tried to cancel it, it *would* inject a `Cancelled` exception,
even though it wasn't cancelled. Most users probably never noticed
either way, but injecting a `Cancelled` here is not really useful, and
in some rare cases caused confusion or problems, so Trio no longer
does that.
1 change: 1 addition & 0 deletions newsfragments/2807.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
On windows, if SIO_BASE_HANDLE failed and SIO_BSP_HANDLE_POLL didn't return a different socket, runtime error will now raise from the OSError that indicated the issue so that in the event it does happen it might help with debugging.
2 changes: 1 addition & 1 deletion notes-to-self/graceful-shutdown-idea.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def stream_handler(stream):
# To trigger the shutdown:
async def listen_for_shutdown_signals():
with trio.open_signal_receiver(signal.SIGINT, signal.SIGTERM) as signal_aiter:
async for sig in signal_aiter:
async for _sig in signal_aiter:
gsm.start_shutdown()
break
# TODO: it'd be nice to have some logic like "if we get another
Expand Down
4 changes: 2 additions & 2 deletions notes-to-self/how-does-windows-so-reuseaddr-work.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def bind(sock, bind_type):
elif bind_type == "specific":
sock.bind(("127.0.0.1", 12345))
else:
assert False
raise AssertionError()


def table_entry(mode1, bind_type1, mode2, bind_type2):
Expand All @@ -53,7 +53,7 @@ def table_entry(mode1, bind_type1, mode2, bind_type2):
)

print(""" """, end="")
for mode in modes:
for _ in modes:
print(" | " + " | ".join(["%8s" % bind_type for bind_type in bind_types]), end="")

print(
Expand Down
4 changes: 3 additions & 1 deletion notes-to-self/loopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
async def loopy():
try:
while True:
time.sleep(0.01)
time.sleep( # noqa: ASYNC101 # synchronous sleep to avoid maxing out CPU
0.01
)
await trio.sleep(0)
except KeyboardInterrupt:
print("KI!")
Expand Down
6 changes: 3 additions & 3 deletions notes-to-self/socketpair-buffering.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
b.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, bufsize)

try:
for i in range(10000000):
for _count in range(10000000):
a.send(b"\x00")
except BlockingIOError:
pass
break

print(f"setsockopt bufsize {bufsize}: {i}")
print(f"setsockopt bufsize {bufsize}: {_count}")
a.close()
b.close()
2 changes: 1 addition & 1 deletion notes-to-self/ssl-close-notify/ssl-close-notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ def server_thread_fn():
except ssl.SSLWantReadError:
print("client got SSLWantReadError as expected")
else:
assert False
raise AssertionError()
client.close()
client_done.set()
4 changes: 1 addition & 3 deletions notes-to-self/thread-closure-bug-demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def traced_looper():
# Force w_locals to be instantiated (only matters on PyPy; on CPython
# you can comment this line out and everything stays the same)
print(locals())
# Force x to be closed over (could use 'nonlocal' on py3)
if False:
x
nonlocal x # Force x to be closed over
# Random nonsense whose only purpose is to trigger lots of calls to
# the trace func
count = 0
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ src = ["trio", "notes-to-self"]

select = [
"RUF", # Ruff-specific rules
"E", # Error
"F", # pyflakes
"E", # Error
"W", # Warning
"I", # isort
"B", # flake8-bugbear
"YTT", # flake8-2020
"ASYNC", # flake8-async
"SIM", # flake8-simplify
]
extend-ignore = [
Expand Down
28 changes: 12 additions & 16 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#
astor==0.8.1
# via -r test-requirements.in
astroid==2.15.8
astroid==3.0.1
# via pylint
async-generator==1.10
# via -r test-requirements.in
attrs==23.1.0
# via
# -r test-requirements.in
# outcome
black==23.9.1 ; implementation_name == "cpython"
black==23.10.0 ; implementation_name == "cpython"
# via -r test-requirements.in
build==1.0.3
# via pip-tools
Expand All @@ -24,9 +24,9 @@ click==8.1.7
# via
# black
# pip-tools
codespell==2.2.5
codespell==2.2.6
# via -r test-requirements.in
coverage==7.3.1
coverage==7.3.2
# via -r test-requirements.in
cryptography==41.0.4
# via
Expand All @@ -50,13 +50,11 @@ iniconfig==2.0.0
# via pytest
isort==5.12.0
# via pylint
jedi==0.19.0
jedi==0.19.1
# via -r test-requirements.in
lazy-object-proxy==1.9.0
# via astroid
mccabe==0.7.0
# via pylint
mypy==1.5.1 ; implementation_name == "cpython"
mypy==1.6.0 ; implementation_name == "cpython"
# via -r test-requirements.in
mypy-extensions==1.0.0 ; implementation_name == "cpython"
# via
Expand All @@ -65,9 +63,9 @@ mypy-extensions==1.0.0 ; implementation_name == "cpython"
# mypy
nodeenv==1.8.0
# via pyright
outcome==1.2.0
outcome==1.3.0
# via -r test-requirements.in
packaging==23.1
packaging==23.2
# via
# black
# build
Expand All @@ -78,25 +76,25 @@ pathspec==0.11.2
# via black
pip-tools==7.3.0
# via -r test-requirements.in
platformdirs==3.10.0
platformdirs==3.11.0
# via
# black
# pylint
pluggy==1.3.0
# via pytest
pycparser==2.21
# via cffi
pylint==2.17.7
pylint==3.0.1
# via -r test-requirements.in
pyopenssl==23.2.0
# via -r test-requirements.in
pyproject-hooks==1.0.0
# via build
pyright==1.1.329
pyright==1.1.331
# via -r test-requirements.in
pytest==7.4.2
# via -r test-requirements.in
ruff==0.0.291
ruff==0.1.0
# via -r test-requirements.in
sniffio==1.3.0
# via -r test-requirements.in
Expand Down Expand Up @@ -130,8 +128,6 @@ typing-extensions==4.8.0
# pylint
wheel==0.41.2
# via pip-tools
wrapt==1.15.0
# via astroid
zipp==3.17.0
# via importlib-metadata

Expand Down
11 changes: 10 additions & 1 deletion trio/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ class Instrument(metaclass=ABCMeta):

def before_run(self) -> None:
"""Called at the beginning of :func:`trio.run`."""
return

def after_run(self) -> None:
"""Called just before :func:`trio.run` returns."""
return

def task_spawned(self, task: Task) -> None:
"""Called when the given task is created.
Expand All @@ -91,6 +93,7 @@ def task_spawned(self, task: Task) -> None:
task (trio.lowlevel.Task): The new task.
"""
return

def task_scheduled(self, task: Task) -> None:
"""Called when the given task becomes runnable.
Expand All @@ -102,6 +105,7 @@ def task_scheduled(self, task: Task) -> None:
task (trio.lowlevel.Task): The task that became runnable.
"""
return

def before_task_step(self, task: Task) -> None:
"""Called immediately before we resume running the given task.
Expand All @@ -110,6 +114,7 @@ def before_task_step(self, task: Task) -> None:
task (trio.lowlevel.Task): The task that is about to run.
"""
return

def after_task_step(self, task: Task) -> None:
"""Called when we return to the main run loop after a task has yielded.
Expand All @@ -118,6 +123,7 @@ def after_task_step(self, task: Task) -> None:
task (trio.lowlevel.Task): The task that just ran.
"""
return

def task_exited(self, task: Task) -> None:
"""Called when the given task exits.
Expand All @@ -126,6 +132,7 @@ def task_exited(self, task: Task) -> None:
task (trio.lowlevel.Task): The finished task.
"""
return

def before_io_wait(self, timeout: float) -> None:
"""Called before blocking to wait for I/O readiness.
Expand All @@ -134,6 +141,7 @@ def before_io_wait(self, timeout: float) -> None:
timeout (float): The number of seconds we are willing to wait.
"""
return

def after_io_wait(self, timeout: float) -> None:
"""Called after handling pending I/O.
Expand All @@ -144,6 +152,7 @@ def after_io_wait(self, timeout: float) -> None:
whether any I/O was ready.
"""
return


class HostnameResolver(metaclass=ABCMeta):
Expand Down Expand Up @@ -679,7 +688,7 @@ async def __anext__(self) -> ReceiveType:
try:
return await self.receive()
except trio.EndOfChannel:
raise StopAsyncIteration
raise StopAsyncIteration from None


class Channel(SendChannel[T], ReceiveChannel[T]):
Expand Down
4 changes: 2 additions & 2 deletions trio/_core/_generated_instrumentation.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions trio/_core/_generated_io_epoll.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e55b1e3

Please sign in to comment.