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 @contextmanager
def async_conversation_trace() -> Generator[ConversationTrace, None]: def async_conversation_trace() -> Generator[ConversationTrace]:
"""Create a new active ConversationTrace.""" """Create a new active ConversationTrace."""
trace = ConversationTrace() trace = ConversationTrace()
token = _current_trace.set(trace) token = _current_trace.set(trace)

View File

@ -60,13 +60,13 @@ class LitterRobotHub:
except LitterRobotException as ex: except LitterRobotException as ex:
raise ConfigEntryNotReady("Unable to connect to Litter-Robot API") from 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.""" """Get Litter-Robots from the account."""
return ( return (
robot for robot in self.account.robots if isinstance(robot, LitterRobot) 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.""" """Get Feeder-Robots from the account."""
return ( return (
robot for robot in self.account.robots if isinstance(robot, FeederRobot) robot for robot in self.account.robots if isinstance(robot, FeederRobot)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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