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 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/how-does-windows-so-reuseaddr-work.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 5 additions & 6 deletions notes-to-self/socketpair-buffering.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
a.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, bufsize)
b.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, bufsize)

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

print(f"setsockopt bufsize {bufsize}: {i}")
print(f"setsockopt bufsize {bufsize}: {_count}")
a.close()
b.close()
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ extend-exclude = [
[tool.ruff.isort]
combine-as-imports = true

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

[tool.mypy]
python_version = "3.8"

Expand Down
4 changes: 2 additions & 2 deletions trio/_core/_tests/test_asyncgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async def async_main() -> None:
# (if the run_sync_soon task runs before init on one tick and after init
# on the next tick); if we try enough times, we can make the chance of
# failure as small as we want.
for attempt in range(50): # noqa: B007 # used if failed
for _attempt in range(50):
needs_retry = False
del record[:]
del saved[:]
Expand All @@ -240,7 +240,7 @@ async def async_main() -> None:
else: # pragma: no cover
pytest.fail(
"Didn't manage to hit the trailing_finalizer_asyncgens case "
f"despite trying {attempt} times"
f"despite trying {_attempt} times"
)


Expand Down
23 changes: 23 additions & 0 deletions trio/_tests/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@
import pytest

from .. import abc as tabc
from ..lowlevel import Task


def test_instrument_implements_hook_methods() -> None:
attrs = {
"before_run": (),
"after_run": (),
"task_spawned": (Task,),
"task_scheduled": (Task,),
"before_task_step": (Task,),
"after_task_step": (Task,),
"task_exited": (Task,),
"before_io_wait": (3.3,),
"after_io_wait": (3.3,),
}

mayonnaise = tabc.Instrument()

for method_name, args in attrs.items():
assert hasattr(mayonnaise, method_name)
method = getattr(mayonnaise, method_name)
assert callable(method)
method(*args)


async def test_AsyncResource_defaults() -> None:
Expand Down
2 changes: 1 addition & 1 deletion trio/_tests/test_deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def test_module_with_deprecations(recwarn_always: pytest.WarningsRecorder) -> No
assert "instead-string instead" in got.message.args[0]

with pytest.raises(AttributeError):
module_with_deprecations.asdf # type: ignore[attr-defined] # noqa
module_with_deprecations.asdf # type: ignore[attr-defined] # noqa: B018
CoolCat467 marked this conversation as resolved.
Show resolved Hide resolved


def test_tests_is_deprecated1() -> None:
Expand Down
2 changes: 1 addition & 1 deletion trio/_tests/test_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def unsupported_attr(self): # pragma: no cover
assert hasattr(async_file.wrapped, "unsupported_attr")

with pytest.raises(AttributeError):
async_file.unsupported_attr # noqa: B018
async_file.unsupported_attr # noqa: B018 # "useless expression"


def test_type_stubs_match_lists() -> None:
Expand Down
2 changes: 1 addition & 1 deletion trio/_tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def test_compare_async_stat_methods(method_name):

async def test_invalid_name_not_wrapped(path):
with pytest.raises(AttributeError):
path.invalid_fake_attr # noqa: B018
getattr(path, "invalid_fake_attr") # noqa: B009 # "get-attr-with-constant"


@pytest.mark.parametrize("method_name", ["absolute", "resolve"])
Expand Down
7 changes: 3 additions & 4 deletions trio/_tests/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,8 +1111,7 @@ async def receiver() -> None:
async def test_many_sockets() -> None:
total = 5000 # Must be more than MAX_AFD_GROUP_SIZE
sockets = []
x = 0
for x in range(total // 2): # noqa: B007 # Used for check below
for _x in range(total // 2):
try:
a, b = stdlib_socket.socketpair()
except OSError as e: # pragma: no cover
Expand All @@ -1126,5 +1125,5 @@ async def test_many_sockets() -> None:
nursery.cancel_scope.cancel()
for sock in sockets:
sock.close()
if x != total // 2 - 1: # pragma: no cover
print(f"Unable to open more than {(x-1)*2} sockets.")
if _x != total // 2 - 1: # pragma: no cover
print(f"Unable to open more than {(_x-1)*2} sockets.")
2 changes: 1 addition & 1 deletion trio/_tests/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ async def test_attributes(client_ctx):
assert s.server_side == False # noqa
assert s.server_hostname == "trio-test-1.example.org"
with pytest.raises(AttributeError):
s.asfdasdfsa # noqa: B018
s.asfdasdfsa # noqa: B018 # "useless expression"

# __dir__
assert "transport_stream" in dir(s)
Expand Down
8 changes: 4 additions & 4 deletions trio/_tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async def test_assert_checkpoints(recwarn):

with pytest.raises(AssertionError):
with assert_checkpoints():
1 + 1 # noqa: B018
1 + 1 # noqa: B018 # "useless expression"

# partial yield cases
# if you have a schedule point but not a cancel point, or vice-versa, then
Expand All @@ -132,7 +132,7 @@ async def test_assert_checkpoints(recwarn):

async def test_assert_no_checkpoints(recwarn):
with assert_no_checkpoints():
1 + 1 # noqa: B018
1 + 1 # noqa: B018 # "useless expression"

with pytest.raises(AssertionError):
with assert_no_checkpoints():
Expand Down Expand Up @@ -233,11 +233,11 @@ async def child(i):
async def test__assert_raises():
with pytest.raises(AssertionError):
with _assert_raises(RuntimeError):
1 + 1 # noqa: B018
1 + 1 # noqa: B018 # "useless expression"

with pytest.raises(TypeError):
with _assert_raises(RuntimeError):
"foo" + 1 # noqa: B018
"foo" + 1 # noqa: B018 # "useless expression"

with _assert_raises(RuntimeError):
raise RuntimeError
Expand Down
2 changes: 1 addition & 1 deletion trio/_tests/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ async def run_thread(event):
async with _core.open_nursery() as nursery:
print("spawning")
events = []
for _i in range(COUNT):
for _ in range(COUNT):
events.append(Event())
nursery.start_soon(run_thread, events[-1])
await wait_all_tasks_blocked()
Expand Down
2 changes: 1 addition & 1 deletion trio/_tests/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def coro2_async_gen(event):


async def coro3_async_gen(event: trio.Event) -> None:
async for _x in coro2_async_gen(event):
async for _ in coro2_async_gen(event):
pass


Expand Down
Loading