Revert aiohttp to 3.8.5 for Python 3.11 (#101932)

This commit is contained in:
Marc Mueller 2023-10-13 14:12:42 +02:00 committed by GitHub
parent 2dfc8b9d7f
commit 02567d9bf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 16 deletions

View file

@ -157,7 +157,7 @@ class HassIOView(HomeAssistantView):
if path == "backups/new/upload":
# We need to reuse the full content type that includes the boundary
# pylint: disable-next=protected-access
headers[CONTENT_TYPE] = request._stored_content_type # type: ignore[assignment]
headers[CONTENT_TYPE] = request._stored_content_type
try:
client = await self._websession.request(

View file

@ -4,6 +4,7 @@ from __future__ import annotations
import asyncio
from collections.abc import Awaitable, Callable
from contextlib import suppress
from ssl import SSLContext
import sys
from types import MappingProxyType
from typing import TYPE_CHECKING, Any, cast
@ -65,8 +66,10 @@ async def _noop_wait(*args: Any, **kwargs: Any) -> None:
return
# pylint: disable-next=protected-access
web.BaseSite._wait = _noop_wait # type: ignore[method-assign]
# TODO: Remove version check with aiohttp 3.9.0 # pylint: disable=fixme
if sys.version_info >= (3, 12):
# pylint: disable-next=protected-access
web.BaseSite._wait = _noop_wait # type: ignore[method-assign]
class HassClientResponse(aiohttp.ClientResponse):
@ -286,7 +289,7 @@ def _async_get_connector(
return cast(aiohttp.BaseConnector, hass.data[key])
if verify_ssl:
ssl_context = ssl_util.get_default_context()
ssl_context: bool | SSLContext = ssl_util.get_default_context()
else:
ssl_context = ssl_util.get_default_no_verify_context()

View file

@ -1,5 +1,6 @@
aiodiscover==1.5.1
aiohttp==3.9.0b0
aiohttp==3.8.5;python_version<'3.12'
aiohttp==3.9.0b0;python_version>='3.12'
aiohttp_cors==0.7.0
astral==2.2
async-upnp-client==0.36.1

View file

@ -23,7 +23,8 @@ classifiers = [
]
requires-python = ">=3.11.0"
dependencies = [
"aiohttp==3.9.0b0",
"aiohttp==3.9.0b0;python_version>='3.12'",
"aiohttp==3.8.5;python_version<'3.12'",
"astral==2.2",
"attrs==23.1.0",
"atomicwrites-homeassistant==1.4.1",

View file

@ -1,7 +1,8 @@
-c homeassistant/package_constraints.txt
# Home Assistant Core
aiohttp==3.9.0b0
aiohttp==3.9.0b0;python_version>='3.12'
aiohttp==3.8.5;python_version<'3.12'
astral==2.2
attrs==23.1.0
atomicwrites-homeassistant==1.4.1

View file

@ -1,6 +1,7 @@
"""The tests for generic camera component."""
import asyncio
from http import HTTPStatus
import sys
from unittest.mock import patch
import aiohttp
@ -163,10 +164,17 @@ async def test_limit_refetch(
hass.states.async_set("sensor.temp", "5")
with pytest.raises(aiohttp.ServerTimeoutError), patch(
"asyncio.timeout", side_effect=asyncio.TimeoutError()
):
resp = await client.get("/api/camera_proxy/camera.config_test")
# TODO: Remove version check with aiohttp 3.9.0
if sys.version_info >= (3, 12):
with pytest.raises(aiohttp.ServerTimeoutError), patch(
"asyncio.timeout", side_effect=asyncio.TimeoutError()
):
resp = await client.get("/api/camera_proxy/camera.config_test")
else:
with pytest.raises(aiohttp.ServerTimeoutError), patch(
"async_timeout.timeout", side_effect=asyncio.TimeoutError()
):
resp = await client.get("/api/camera_proxy/camera.config_test")
assert respx.calls.call_count == 1
assert resp.status == HTTPStatus.OK

View file

@ -1,4 +1,6 @@
"""Test aiohttp request helper."""
import sys
from aiohttp import web
from homeassistant.util import aiohttp
@ -48,11 +50,22 @@ def test_serialize_text() -> None:
def test_serialize_body_str() -> None:
"""Test serializing a response with a str as body."""
response = web.Response(status=201, body="Hello")
assert aiohttp.serialize_response(response) == {
"status": 201,
"body": "Hello",
"headers": {"Content-Type": "text/plain; charset=utf-8"},
}
# TODO: Remove version check with aiohttp 3.9.0
if sys.version_info >= (3, 12):
assert aiohttp.serialize_response(response) == {
"status": 201,
"body": "Hello",
"headers": {"Content-Type": "text/plain; charset=utf-8"},
}
else:
assert aiohttp.serialize_response(response) == {
"status": 201,
"body": "Hello",
"headers": {
"Content-Length": "5",
"Content-Type": "text/plain; charset=utf-8",
},
}
def test_serialize_body_None() -> None: