Skip to content
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

Enable flake8-bugbear rule #2807

Merged
merged 15 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 _mode in modes:
print(" | " + " | ".join(["%8s" % bind_type for bind_type in bind_types]), end="")

print(
Expand Down
9 changes: 5 additions & 4 deletions notes-to-self/socketpair-buffering.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
a.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, bufsize)
b.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, bufsize)

try:
for i in range(10000000):
i = 0
for i in range(10000000): # noqa: B007 # i unused inside loop
try:
a.send(b"\x00")
except BlockingIOError:
pass
except BlockingIOError:
break

print(f"setsockopt bufsize {bufsize}: {i}")
a.close()
Expand Down
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
7 changes: 6 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 Expand Up @@ -54,6 +56,9 @@ extend-exclude = [
[tool.ruff.isort]
combine-as-imports = true

[tool.ruff.flake8-annotations]
ignore-fully-untyped = true

CoolCat467 marked this conversation as resolved.
Show resolved Hide resolved
[tool.mypy]
python_version = "3.8"

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 @@

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

Check warning on line 83 in trio/_abc.py

View check run for this annotation

Codecov / codecov/patch

trio/_abc.py#L83

Added line #L83 was not covered by tests
CoolCat467 marked this conversation as resolved.
Show resolved Hide resolved

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

Check warning on line 87 in trio/_abc.py

View check run for this annotation

Codecov / codecov/patch

trio/_abc.py#L87

Added line #L87 was not covered by tests

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

"""
return

Check warning on line 96 in trio/_abc.py

View check run for this annotation

Codecov / codecov/patch

trio/_abc.py#L96

Added line #L96 was not covered by tests

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

"""
return

Check warning on line 108 in trio/_abc.py

View check run for this annotation

Codecov / codecov/patch

trio/_abc.py#L108

Added line #L108 was not covered by tests

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

"""
return

Check warning on line 117 in trio/_abc.py

View check run for this annotation

Codecov / codecov/patch

trio/_abc.py#L117

Added line #L117 was not covered by tests

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 @@
task (trio.lowlevel.Task): The task that just ran.

"""
return

Check warning on line 126 in trio/_abc.py

View check run for this annotation

Codecov / codecov/patch

trio/_abc.py#L126

Added line #L126 was not covered by tests

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

"""
return

Check warning on line 135 in trio/_abc.py

View check run for this annotation

Codecov / codecov/patch

trio/_abc.py#L135

Added line #L135 was not covered by tests

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

"""
return

Check warning on line 144 in trio/_abc.py

View check run for this annotation

Codecov / codecov/patch

trio/_abc.py#L144

Added line #L144 was not covered by tests

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

"""
return

Check warning on line 155 in trio/_abc.py

View check run for this annotation

Codecov / codecov/patch

trio/_abc.py#L155

Added line #L155 was not covered by tests


class HostnameResolver(metaclass=ABCMeta):
Expand Down Expand Up @@ -679,7 +688,7 @@
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.

Loading
Loading