Skip to content

Enable flake8-bugbear rule #2807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ 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
Comment on lines 25 to 31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you moved "E" ... probably want this list sorted?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider running a toml-formatter in pre-commit that does it automatically

]
extend-ignore = [
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.

12 changes: 6 additions & 6 deletions trio/_core/_generated_io_kqueue.py

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

18 changes: 9 additions & 9 deletions trio/_core/_generated_io_windows.py

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

16 changes: 8 additions & 8 deletions trio/_core/_generated_run.py

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

2 changes: 1 addition & 1 deletion trio/_core/_io_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def _get_base_socket(sock: _HasFileNo | int | Handle) -> Handle:
"https://github.com/python-trio/trio/issues/new, "
"and include the output of running: "
"netsh winsock show catalog"
)
) from ex
# Otherwise we've gotten at least one layer deeper, so
# loop back around to keep digging.
sock = next_sock
Expand Down
Loading