Enable ruff asyncio event loop blocking detection rules (#120799)
parent
43e4223a8e
commit
aa74ad0061
|
@ -681,6 +681,12 @@ required-version = ">=0.5.0"
|
|||
[tool.ruff.lint]
|
||||
select = [
|
||||
"A001", # Variable {name} is shadowing a Python builtin
|
||||
"ASYNC210", # Async functions should not call blocking HTTP methods
|
||||
"ASYNC220", # Async functions should not create subprocesses with blocking methods
|
||||
"ASYNC221", # Async functions should not run processes with blocking methods
|
||||
"ASYNC222", # Async functions should not wait on processes with blocking methods
|
||||
"ASYNC230", # Async functions should not open files with blocking methods like open
|
||||
"ASYNC251", # Async functions should not call time.sleep
|
||||
"B002", # Python does not support the unary prefix increment
|
||||
"B005", # Using .strip() with multi-character strings is misleading
|
||||
"B007", # Loop control variable {name} not used within loop body
|
||||
|
|
|
@ -80,7 +80,7 @@ async def test_srp_entity_timeout(
|
|||
):
|
||||
client = srp_energy_mock.return_value
|
||||
client.validate.return_value = True
|
||||
client.usage = lambda _, __, ___: time.sleep(1)
|
||||
client.usage = lambda _, __, ___: time.sleep(1) # noqa: ASYNC251
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
|
|
|
@ -44,7 +44,7 @@ async def test_protect_loop_debugger_sleep(caplog: pytest.LogCaptureFixture) ->
|
|||
return_value=frames,
|
||||
),
|
||||
):
|
||||
time.sleep(0)
|
||||
time.sleep(0) # noqa: ASYNC251
|
||||
assert "Detected blocking call inside the event loop" not in caplog.text
|
||||
|
||||
|
||||
|
@ -71,7 +71,7 @@ async def test_protect_loop_sleep() -> None:
|
|||
return_value=frames,
|
||||
),
|
||||
):
|
||||
time.sleep(0)
|
||||
time.sleep(0) # noqa: ASYNC251
|
||||
|
||||
|
||||
async def test_protect_loop_sleep_get_current_frame_raises() -> None:
|
||||
|
@ -97,7 +97,7 @@ async def test_protect_loop_sleep_get_current_frame_raises() -> None:
|
|||
return_value=frames,
|
||||
),
|
||||
):
|
||||
time.sleep(0)
|
||||
time.sleep(0) # noqa: ASYNC251
|
||||
|
||||
|
||||
async def test_protect_loop_importlib_import_module_non_integration(
|
||||
|
@ -211,7 +211,7 @@ async def test_protect_loop_open(caplog: pytest.LogCaptureFixture) -> None:
|
|||
block_async_io.enable()
|
||||
with (
|
||||
contextlib.suppress(FileNotFoundError),
|
||||
open("/proc/does_not_exist", encoding="utf8"),
|
||||
open("/proc/does_not_exist", encoding="utf8"), # noqa: ASYNC230
|
||||
):
|
||||
pass
|
||||
assert "Detected blocking call to open with args" not in caplog.text
|
||||
|
@ -223,7 +223,7 @@ async def test_protect_open(caplog: pytest.LogCaptureFixture) -> None:
|
|||
block_async_io.enable()
|
||||
with (
|
||||
contextlib.suppress(FileNotFoundError),
|
||||
open("/config/data_not_exist", encoding="utf8"),
|
||||
open("/config/data_not_exist", encoding="utf8"), # noqa: ASYNC230
|
||||
):
|
||||
pass
|
||||
|
||||
|
@ -253,7 +253,7 @@ async def test_protect_open_path(path: Any, caplog: pytest.LogCaptureFixture) ->
|
|||
"""Test opening a file by path in the event loop logs."""
|
||||
with patch.object(block_async_io, "_IN_TESTS", False):
|
||||
block_async_io.enable()
|
||||
with contextlib.suppress(FileNotFoundError), open(path, encoding="utf8"):
|
||||
with contextlib.suppress(FileNotFoundError), open(path, encoding="utf8"): # noqa: ASYNC230
|
||||
pass
|
||||
|
||||
assert "Detected blocking call to open with args" in caplog.text
|
||||
|
@ -336,7 +336,7 @@ async def test_open_calls_ignored_in_tests(caplog: pytest.LogCaptureFixture) ->
|
|||
block_async_io.enable()
|
||||
with (
|
||||
contextlib.suppress(FileNotFoundError),
|
||||
open("/config/data_not_exist", encoding="utf8"),
|
||||
open("/config/data_not_exist", encoding="utf8"), # noqa: ASYNC230
|
||||
):
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in New Issue