Use TypeVar defaults for Generator (#122170)

This commit is contained in:
Marc Mueller 2024-07-19 13:06:45 +02:00 committed by GitHub
parent 2b486c3bd5
commit c92d9dcb74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 22 additions and 26 deletions

View file

@ -94,7 +94,7 @@ def async_conversation_trace_append(
@contextmanager
def async_conversation_trace() -> Generator[ConversationTrace, None]:
def async_conversation_trace() -> Generator[ConversationTrace]:
"""Create a new active ConversationTrace."""
trace = ConversationTrace()
token = _current_trace.set(trace)

View file

@ -60,13 +60,13 @@ class LitterRobotHub:
except LitterRobotException as ex:
raise ConfigEntryNotReady("Unable to connect to Litter-Robot API") from ex
def litter_robots(self) -> Generator[LitterRobot, Any, Any]:
def litter_robots(self) -> Generator[LitterRobot]:
"""Get Litter-Robots from the account."""
return (
robot for robot in self.account.robots if isinstance(robot, LitterRobot)
)
def feeder_robots(self) -> Generator[FeederRobot, Any, Any]:
def feeder_robots(self) -> Generator[FeederRobot]:
"""Get Feeder-Robots from the account."""
return (
robot for robot in self.account.robots if isinstance(robot, FeederRobot)

View file

@ -24,7 +24,7 @@ MOCK_COVER_DEVICE = {
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.chacon_dio.async_setup_entry", return_value=True

View file

@ -42,7 +42,7 @@ def doorbird_schedule() -> list[DoorBirdScheduleEntry]:
@pytest.fixture
def doorbird_api(
doorbird_info: dict[str, Any], doorbird_schedule: dict[str, Any]
) -> Generator[Any, Any, DoorBird]:
) -> Generator[DoorBird]:
"""Mock the DoorBirdAPI."""
api = get_mock_doorbird_api(info=doorbird_info, schedule=doorbird_schedule)
with patch_doorbird_api_entry_points(api):
@ -50,7 +50,7 @@ def doorbird_api(
@contextmanager
def patch_doorbird_api_entry_points(api: MagicMock) -> Generator[Any, Any, DoorBird]:
def patch_doorbird_api_entry_points(api: MagicMock) -> Generator[DoorBird]:
"""Mock the DoorBirdAPI."""
with (
patch(

View file

@ -67,7 +67,7 @@ def config_fixture() -> dict[str, str]:
@pytest.fixture
async def mock_envoy(
request: pytest.FixtureRequest,
) -> AsyncGenerator[AsyncMock, None]:
) -> AsyncGenerator[AsyncMock]:
"""Define a mocked Envoy fixture."""
with (
patch(

View file

@ -1,7 +1,6 @@
"""Tests for home_connect light entities."""
from collections.abc import Awaitable, Callable, Generator
from typing import Any
from unittest.mock import MagicMock, Mock
from homeconnect.api import HomeConnectError
@ -48,7 +47,7 @@ def platforms() -> list[str]:
async def test_light(
bypass_throttle: Generator[None, Any, None],
bypass_throttle: Generator[None],
hass: HomeAssistant,
config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]],
@ -159,7 +158,7 @@ async def test_light_functionality(
service_data: dict,
state: str,
appliance: Mock,
bypass_throttle: Generator[None, Any, None],
bypass_throttle: Generator[None],
hass: HomeAssistant,
config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]],
@ -273,7 +272,7 @@ async def test_switch_exception_handling(
mock_attr: str,
attr_side_effect: list,
problematic_appliance: Mock,
bypass_throttle: Generator[None, Any, None],
bypass_throttle: Generator[None],
hass: HomeAssistant,
integration_setup: Callable[[], Awaitable[bool]],
config_entry: MockConfigEntry,

View file

@ -1,7 +1,6 @@
"""Tests for home_connect sensor entities."""
from collections.abc import Awaitable, Callable, Generator
from typing import Any
from unittest.mock import MagicMock, Mock
from homeconnect.api import HomeConnectError
@ -48,7 +47,7 @@ def platforms() -> list[str]:
async def test_switches(
bypass_throttle: Generator[None, Any, None],
bypass_throttle: Generator[None],
hass: HomeAssistant,
config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]],
@ -119,7 +118,7 @@ async def test_switch_functionality(
status: dict,
service: str,
state: str,
bypass_throttle: Generator[None, Any, None],
bypass_throttle: Generator[None],
hass: HomeAssistant,
config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]],
@ -189,7 +188,7 @@ async def test_switch_exception_handling(
status: dict,
service: str,
mock_attr: str,
bypass_throttle: Generator[None, Any, None],
bypass_throttle: Generator[None],
hass: HomeAssistant,
integration_setup: Callable[[], Awaitable[bool]],
config_entry: MockConfigEntry,

View file

@ -14,7 +14,7 @@ from tests.common import MockConfigEntry
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.madvr.async_setup_entry",
@ -24,7 +24,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
@pytest.fixture
def mock_madvr_client() -> Generator[AsyncMock, None, None]:
def mock_madvr_client() -> Generator[AsyncMock]:
"""Mock a MadVR client."""
with (
patch(

View file

@ -17,7 +17,7 @@ from tests.common import MockConfigEntry
@pytest.fixture(autouse=True)
async def avoid_wait() -> AsyncGenerator[None, None]:
async def avoid_wait() -> AsyncGenerator[None]:
"""Mock sleep."""
with patch("homeassistant.components.madvr.config_flow.RETRY_INTERVAL", 0):
yield

View file

@ -67,9 +67,7 @@ DEFAULT_CONFIG = {
}
def _test_run_select_setup_params(
topic: str,
) -> Generator[tuple[ConfigType, str], None]:
def _test_run_select_setup_params(topic: str) -> Generator[tuple[ConfigType, str]]:
yield (
{
mqtt.DOMAIN: {
@ -593,7 +591,7 @@ async def test_entity_debug_info_message(
def _test_options_attributes_options_config(
request: tuple[list[str]],
) -> Generator[tuple[ConfigType, list[str]], None]:
) -> Generator[tuple[ConfigType, list[str]]]:
for option in request:
yield (
{

View file

@ -16,7 +16,7 @@ MOCK_ACCESS_URL = "https://i:am@yomama.house.com"
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
def mock_setup_entry() -> Generator[AsyncMock]:
"""Mock setting up a config entry."""
with patch(
"homeassistant.components.simplefin.async_setup_entry", return_value=True

View file

@ -64,7 +64,7 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture(autouse=True)
def mock_setup_notify_platform() -> Generator[AsyncMock, None, None]:
def mock_setup_notify_platform() -> Generator[AsyncMock]:
"""Mock notify platform setup."""
with patch(
"homeassistant.helpers.discovery.async_load_platform",
@ -73,7 +73,7 @@ def mock_setup_notify_platform() -> Generator[AsyncMock, None, None]:
@pytest.fixture
def mock_version() -> Generator[AsyncMock, None, None]:
def mock_version() -> Generator[AsyncMock]:
"""Return a mocked Version class."""
with patch(
"homeassistant.components.system_bridge.Version",
@ -90,7 +90,7 @@ def mock_websocket_client(
register_data_listener_model: RegisterDataListener = RegisterDataListener(
modules=REGISTER_MODULES,
),
) -> Generator[MagicMock, None, None]:
) -> Generator[MagicMock]:
"""Return a mocked WebSocketClient client."""
with (