diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c662c6754f4..f85f8583a04 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.272 + rev: v0.0.277 hooks: - id: ruff args: diff --git a/homeassistant/components/amcrest/__init__.py b/homeassistant/components/amcrest/__init__.py index 8fea717e6bb..ce07741c37f 100644 --- a/homeassistant/components/amcrest/__init__.py +++ b/homeassistant/components/amcrest/__init__.py @@ -210,9 +210,10 @@ class AmcrestChecker(ApiWrapper): self, *args: Any, **kwargs: Any ) -> AsyncIterator[httpx.Response]: """amcrest.ApiWrapper.command wrapper to catch errors.""" - async with self._async_command_wrapper(): - async with super().async_stream_command(*args, **kwargs) as ret: - yield ret + async with self._async_command_wrapper(), super().async_stream_command( + *args, **kwargs + ) as ret: + yield ret @asynccontextmanager async def _async_command_wrapper(self) -> AsyncIterator[None]: diff --git a/homeassistant/components/auth/indieauth.py b/homeassistant/components/auth/indieauth.py index ec8431366ab..e2614af6a3e 100644 --- a/homeassistant/components/auth/indieauth.py +++ b/homeassistant/components/auth/indieauth.py @@ -92,14 +92,15 @@ async def fetch_redirect_uris(hass: HomeAssistant, url: str) -> list[str]: parser = LinkTagParser("redirect_uri") chunks = 0 try: - async with aiohttp.ClientSession() as session: - async with session.get(url, timeout=5) as resp: - async for data in resp.content.iter_chunked(1024): - parser.feed(data.decode()) - chunks += 1 + async with aiohttp.ClientSession() as session, session.get( + url, timeout=5 + ) as resp: + async for data in resp.content.iter_chunked(1024): + parser.feed(data.decode()) + chunks += 1 - if chunks == 10: - break + if chunks == 10: + break except asyncio.TimeoutError: _LOGGER.error("Timeout while looking up redirect_uri %s", url) diff --git a/requirements_test_pre_commit.txt b/requirements_test_pre_commit.txt index eff26bcfe82..4047daf73cf 100644 --- a/requirements_test_pre_commit.txt +++ b/requirements_test_pre_commit.txt @@ -2,5 +2,5 @@ black==23.3.0 codespell==2.2.2 -ruff==0.0.272 +ruff==0.0.277 yamllint==1.28.0 diff --git a/tests/util/test_timeout.py b/tests/util/test_timeout.py index e89c6cd3f02..f301cd3c634 100644 --- a/tests/util/test_timeout.py +++ b/tests/util/test_timeout.py @@ -31,9 +31,8 @@ async def test_simple_global_timeout_freeze() -> None: """Test a simple global timeout freeze.""" timeout = TimeoutManager() - async with timeout.async_timeout(0.2): - async with timeout.async_freeze(): - await asyncio.sleep(0.3) + async with timeout.async_timeout(0.2), timeout.async_freeze(): + await asyncio.sleep(0.3) async def test_simple_zone_timeout_freeze_inside_executor_job( @@ -46,9 +45,10 @@ async def test_simple_zone_timeout_freeze_inside_executor_job( with timeout.freeze("recorder"): time.sleep(0.3) - async with timeout.async_timeout(1.0): - async with timeout.async_timeout(0.2, zone_name="recorder"): - await hass.async_add_executor_job(_some_sync_work) + async with timeout.async_timeout(1.0), timeout.async_timeout( + 0.2, zone_name="recorder" + ): + await hass.async_add_executor_job(_some_sync_work) async def test_simple_global_timeout_freeze_inside_executor_job( @@ -75,9 +75,10 @@ async def test_mix_global_timeout_freeze_and_zone_freeze_inside_executor_job( with timeout.freeze("recorder"): time.sleep(0.3) - async with timeout.async_timeout(0.1): - async with timeout.async_timeout(0.2, zone_name="recorder"): - await hass.async_add_executor_job(_some_sync_work) + async with timeout.async_timeout(0.1), timeout.async_timeout( + 0.2, zone_name="recorder" + ): + await hass.async_add_executor_job(_some_sync_work) async def test_mix_global_timeout_freeze_and_zone_freeze_different_order( @@ -108,9 +109,10 @@ async def test_mix_global_timeout_freeze_and_zone_freeze_other_zone_inside_execu with pytest.raises(asyncio.TimeoutError): async with timeout.async_timeout(0.1): - async with timeout.async_timeout(0.2, zone_name="recorder"): - async with timeout.async_timeout(0.2, zone_name="not_recorder"): - await hass.async_add_executor_job(_some_sync_work) + async with timeout.async_timeout( + 0.2, zone_name="recorder" + ), timeout.async_timeout(0.2, zone_name="not_recorder"): + await hass.async_add_executor_job(_some_sync_work) async def test_mix_global_timeout_freeze_and_zone_freeze_inside_executor_job_second_job_outside_zone_context( @@ -136,9 +138,8 @@ async def test_simple_global_timeout_freeze_with_executor_job( """Test a simple global timeout freeze with executor job.""" timeout = TimeoutManager() - async with timeout.async_timeout(0.2): - async with timeout.async_freeze(): - await hass.async_add_executor_job(lambda: time.sleep(0.3)) + async with timeout.async_timeout(0.2), timeout.async_freeze(): + await hass.async_add_executor_job(lambda: time.sleep(0.3)) async def test_simple_global_timeout_freeze_reset() -> None: @@ -185,18 +186,16 @@ async def test_simple_zone_timeout_freeze() -> None: """Test a simple zone timeout freeze.""" timeout = TimeoutManager() - async with timeout.async_timeout(0.2, "test"): - async with timeout.async_freeze("test"): - await asyncio.sleep(0.3) + async with timeout.async_timeout(0.2, "test"), timeout.async_freeze("test"): + await asyncio.sleep(0.3) async def test_simple_zone_timeout_freeze_without_timeout() -> None: """Test a simple zone timeout freeze on a zone that does not have a timeout set.""" timeout = TimeoutManager() - async with timeout.async_timeout(0.1, "test"): - async with timeout.async_freeze("test"): - await asyncio.sleep(0.3) + async with timeout.async_timeout(0.1, "test"), timeout.async_freeze("test"): + await asyncio.sleep(0.3) async def test_simple_zone_timeout_freeze_reset() -> None: @@ -214,29 +213,28 @@ async def test_mix_zone_timeout_freeze_and_global_freeze() -> None: """Test a mix zone timeout freeze and global freeze.""" timeout = TimeoutManager() - async with timeout.async_timeout(0.2, "test"): - async with timeout.async_freeze("test"): - async with timeout.async_freeze(): - await asyncio.sleep(0.3) + async with timeout.async_timeout(0.2, "test"), timeout.async_freeze( + "test" + ), timeout.async_freeze(): + await asyncio.sleep(0.3) async def test_mix_global_and_zone_timeout_freeze_() -> None: """Test a mix zone timeout freeze and global freeze.""" timeout = TimeoutManager() - async with timeout.async_timeout(0.2, "test"): - async with timeout.async_freeze(): - async with timeout.async_freeze("test"): - await asyncio.sleep(0.3) + async with timeout.async_timeout( + 0.2, "test" + ), timeout.async_freeze(), timeout.async_freeze("test"): + await asyncio.sleep(0.3) async def test_mix_zone_timeout_freeze() -> None: """Test a mix zone timeout global freeze.""" timeout = TimeoutManager() - async with timeout.async_timeout(0.2, "test"): - async with timeout.async_freeze(): - await asyncio.sleep(0.3) + async with timeout.async_timeout(0.2, "test"), timeout.async_freeze(): + await asyncio.sleep(0.3) async def test_mix_zone_timeout() -> None: