Enable Ruff RUF013 (#115333)
This commit is contained in:
parent
7e1a5b19c4
commit
3efee10b95
28 changed files with 65 additions and 58 deletions
|
@ -644,6 +644,7 @@ select = [
|
|||
"RSE", # flake8-raise
|
||||
"RUF005", # Consider iterable unpacking instead of concatenation
|
||||
"RUF006", # Store a reference to the return value of asyncio.create_task
|
||||
"RUF013", # PEP 484 prohibits implicit Optional
|
||||
# "RUF100", # Unused `noqa` directive; temporarily every now and then to clean them up
|
||||
"S102", # Use of exec detected
|
||||
"S103", # bad-file-permissions
|
||||
|
|
|
@ -189,7 +189,9 @@ class Client:
|
|||
self.client = client
|
||||
self.id = 0
|
||||
|
||||
async def cmd(self, cmd: str, payload: dict[str, Any] = None) -> dict[str, Any]:
|
||||
async def cmd(
|
||||
self, cmd: str, payload: dict[str, Any] | None = None
|
||||
) -> dict[str, Any]:
|
||||
"""Send a command and receive the json result."""
|
||||
self.id += 1
|
||||
await self.client.send_json(
|
||||
|
@ -203,7 +205,7 @@ class Client:
|
|||
assert resp.get("id") == self.id
|
||||
return resp
|
||||
|
||||
async def cmd_result(self, cmd: str, payload: dict[str, Any] = None) -> Any:
|
||||
async def cmd_result(self, cmd: str, payload: dict[str, Any] | None = None) -> Any:
|
||||
"""Send a command and parse the result."""
|
||||
resp = await self.cmd(cmd, payload)
|
||||
assert resp.get("success")
|
||||
|
|
|
@ -54,9 +54,9 @@ async def setup_mocked_integration(hass: HomeAssistant) -> MockConfigEntry:
|
|||
|
||||
def check_remote_service_call(
|
||||
router: respx.MockRouter,
|
||||
remote_service: str = None,
|
||||
remote_service_params: dict = None,
|
||||
remote_service_payload: dict = None,
|
||||
remote_service: str | None = None,
|
||||
remote_service_params: dict | None = None,
|
||||
remote_service_payload: dict | None = None,
|
||||
):
|
||||
"""Check if the last call was a successful remote service call."""
|
||||
|
||||
|
|
|
@ -83,11 +83,11 @@ async def setup_platform(
|
|||
discovered_device: dict[str, Any],
|
||||
*,
|
||||
bond_device_id: str = "bond-device-id",
|
||||
bond_version: dict[str, Any] = None,
|
||||
props: dict[str, Any] = None,
|
||||
state: dict[str, Any] = None,
|
||||
bridge: dict[str, Any] = None,
|
||||
token: dict[str, Any] = None,
|
||||
bond_version: dict[str, Any] | None = None,
|
||||
props: dict[str, Any] | None = None,
|
||||
state: dict[str, Any] | None = None,
|
||||
bridge: dict[str, Any] | None = None,
|
||||
token: dict[str, Any] | None = None,
|
||||
):
|
||||
"""Set up the specified Bond platform."""
|
||||
mock_entry = MockConfigEntry(
|
||||
|
|
|
@ -7,7 +7,7 @@ from unittest.mock import MagicMock, patch
|
|||
|
||||
@contextmanager
|
||||
def mock_asyncio_subprocess_run(
|
||||
response: bytes = b"", returncode: int = 0, exception: Exception = None
|
||||
response: bytes = b"", returncode: int = 0, exception: Exception | None = None
|
||||
):
|
||||
"""Mock create_subprocess_shell."""
|
||||
|
||||
|
|
|
@ -30,14 +30,14 @@ from tests.common import MockPlatform, mock_platform
|
|||
@bind_hass
|
||||
def async_see(
|
||||
hass: HomeAssistant,
|
||||
mac: str = None,
|
||||
dev_id: str = None,
|
||||
host_name: str = None,
|
||||
location_name: str = None,
|
||||
gps: GPSType = None,
|
||||
mac: str | None = None,
|
||||
dev_id: str | None = None,
|
||||
host_name: str | None = None,
|
||||
location_name: str | None = None,
|
||||
gps: GPSType | None = None,
|
||||
gps_accuracy=None,
|
||||
battery: int = None,
|
||||
attributes: dict = None,
|
||||
battery: int | None = None,
|
||||
attributes: dict | None = None,
|
||||
):
|
||||
"""Call service to notify you see device."""
|
||||
data = {
|
||||
|
|
|
@ -29,7 +29,7 @@ def discord_aiohttp_mock_factory(
|
|||
"""Create Discord service mock from factory."""
|
||||
|
||||
def _discord_aiohttp_mock_factory(
|
||||
headers: dict[str, str] = None,
|
||||
headers: dict[str, str] | None = None,
|
||||
) -> AiohttpClientMocker:
|
||||
if headers is not None:
|
||||
aioclient_mock.get(
|
||||
|
|
|
@ -32,8 +32,8 @@ from tests.common import MockEntity
|
|||
async def async_turn_on(
|
||||
hass,
|
||||
entity_id=ENTITY_MATCH_ALL,
|
||||
percentage: int = None,
|
||||
preset_mode: str = None,
|
||||
percentage: int | None = None,
|
||||
preset_mode: str | None = None,
|
||||
) -> None:
|
||||
"""Turn all or specified fan on."""
|
||||
data = {
|
||||
|
@ -76,7 +76,7 @@ async def async_oscillate(
|
|||
|
||||
|
||||
async def async_set_preset_mode(
|
||||
hass, entity_id=ENTITY_MATCH_ALL, preset_mode: str = None
|
||||
hass, entity_id=ENTITY_MATCH_ALL, preset_mode: str | None = None
|
||||
) -> None:
|
||||
"""Set preset mode for all or specified fan."""
|
||||
data = {
|
||||
|
@ -90,7 +90,7 @@ async def async_set_preset_mode(
|
|||
|
||||
|
||||
async def async_set_percentage(
|
||||
hass, entity_id=ENTITY_MATCH_ALL, percentage: int = None
|
||||
hass, entity_id=ENTITY_MATCH_ALL, percentage: int | None = None
|
||||
) -> None:
|
||||
"""Set percentage for all or specified fan."""
|
||||
data = {
|
||||
|
@ -104,7 +104,7 @@ async def async_set_percentage(
|
|||
|
||||
|
||||
async def async_increase_speed(
|
||||
hass, entity_id=ENTITY_MATCH_ALL, percentage_step: int = None
|
||||
hass, entity_id=ENTITY_MATCH_ALL, percentage_step: int | None = None
|
||||
) -> None:
|
||||
"""Increase speed for all or specified fan."""
|
||||
data = {
|
||||
|
@ -121,7 +121,7 @@ async def async_increase_speed(
|
|||
|
||||
|
||||
async def async_decrease_speed(
|
||||
hass, entity_id=ENTITY_MATCH_ALL, percentage_step: int = None
|
||||
hass, entity_id=ENTITY_MATCH_ALL, percentage_step: int | None = None
|
||||
) -> None:
|
||||
"""Decrease speed for all or specified fan."""
|
||||
data = {
|
||||
|
@ -138,7 +138,7 @@ async def async_decrease_speed(
|
|||
|
||||
|
||||
async def async_set_direction(
|
||||
hass, entity_id=ENTITY_MATCH_ALL, direction: str = None
|
||||
hass, entity_id=ENTITY_MATCH_ALL, direction: str | None = None
|
||||
) -> None:
|
||||
"""Set direction for all or specified fan."""
|
||||
data = {
|
||||
|
|
|
@ -23,9 +23,9 @@ async def setup_config_entry(
|
|||
hass: HomeAssistant,
|
||||
data: dict[str, Any],
|
||||
unique_id: str = "any",
|
||||
device: Mock = None,
|
||||
fritz: Mock = None,
|
||||
template: Mock = None,
|
||||
device: Mock | None = None,
|
||||
fritz: Mock | None = None,
|
||||
template: Mock | None = None,
|
||||
) -> bool:
|
||||
"""Do setup of a MockConfigEntry."""
|
||||
entry = MockConfigEntry(
|
||||
|
|
|
@ -241,7 +241,7 @@ def mock_events_list(
|
|||
|
||||
def _put_result(
|
||||
response: dict[str, Any],
|
||||
calendar_id: str = None,
|
||||
calendar_id: str | None = None,
|
||||
exc: ClientError | None = None,
|
||||
) -> None:
|
||||
if calendar_id is None:
|
||||
|
|
|
@ -79,7 +79,9 @@ class Client:
|
|||
self.client = client
|
||||
self.id = 0
|
||||
|
||||
async def cmd(self, cmd: str, payload: dict[str, Any] = None) -> dict[str, Any]:
|
||||
async def cmd(
|
||||
self, cmd: str, payload: dict[str, Any] | None = None
|
||||
) -> dict[str, Any]:
|
||||
"""Send a command and receive the json result."""
|
||||
self.id += 1
|
||||
await self.client.send_json(
|
||||
|
@ -93,7 +95,7 @@ class Client:
|
|||
assert resp.get("id") == self.id
|
||||
return resp
|
||||
|
||||
async def cmd_result(self, cmd: str, payload: dict[str, Any] = None) -> Any:
|
||||
async def cmd_result(self, cmd: str, payload: dict[str, Any] | None = None) -> Any:
|
||||
"""Send a command and parse the result."""
|
||||
resp = await self.cmd(cmd, payload)
|
||||
assert resp.get("success")
|
||||
|
|
|
@ -101,7 +101,7 @@ async def async_turn_off(hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL) -> Non
|
|||
|
||||
|
||||
async def async_set_mode(
|
||||
hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL, mode: str = None
|
||||
hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL, mode: str | None = None
|
||||
) -> None:
|
||||
"""Set mode for all or specified humidifier."""
|
||||
data = {
|
||||
|
@ -114,7 +114,7 @@ async def async_set_mode(
|
|||
|
||||
|
||||
async def async_set_humidity(
|
||||
hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL, humidity: int = None
|
||||
hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL, humidity: int | None = None
|
||||
) -> None:
|
||||
"""Set target humidity for all or specified humidifier."""
|
||||
data = {
|
||||
|
|
|
@ -148,7 +148,9 @@ class CreateDevice:
|
|||
self.data = {"traits": {}}
|
||||
|
||||
def create(
|
||||
self, raw_traits: dict[str, Any] = None, raw_data: dict[str, Any] = None
|
||||
self,
|
||||
raw_traits: dict[str, Any] | None = None,
|
||||
raw_data: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
"""Create a new device with the specifeid traits."""
|
||||
data = copy.deepcopy(self.data)
|
||||
|
|
|
@ -104,7 +104,7 @@ def webrtc_camera_device(create_device: CreateDevice) -> None:
|
|||
def make_motion_event(
|
||||
event_id: str = MOTION_EVENT_ID,
|
||||
event_session_id: str = EVENT_SESSION_ID,
|
||||
timestamp: datetime.datetime = None,
|
||||
timestamp: datetime.datetime | None = None,
|
||||
) -> EventMessage:
|
||||
"""Create an EventMessage for a motion event."""
|
||||
if not timestamp:
|
||||
|
@ -128,7 +128,7 @@ def make_motion_event(
|
|||
|
||||
|
||||
def make_stream_url_response(
|
||||
expiration: datetime.datetime = None, token_num: int = 0
|
||||
expiration: datetime.datetime | None = None, token_num: int = 0
|
||||
) -> aiohttp.web.Response:
|
||||
"""Make response for the API that generates a streaming url."""
|
||||
if not expiration:
|
||||
|
|
|
@ -152,7 +152,7 @@ class OAuthFixture:
|
|||
)
|
||||
|
||||
async def async_finish_setup(
|
||||
self, result: dict, user_input: dict = None
|
||||
self, result: dict, user_input: dict | None = None
|
||||
) -> ConfigEntry:
|
||||
"""Finish the OAuth flow exchanging auth token for refresh token."""
|
||||
with patch(
|
||||
|
|
|
@ -33,14 +33,14 @@ def _get_mock_nutclient(
|
|||
|
||||
async def async_init_integration(
|
||||
hass: HomeAssistant,
|
||||
ups_fixture: str = None,
|
||||
ups_fixture: str | None = None,
|
||||
username: str = "mock",
|
||||
password: str = "mock",
|
||||
list_ups: dict[str, str] = None,
|
||||
list_vars: dict[str, str] = None,
|
||||
list_commands_return_value: dict[str, str] = None,
|
||||
list_ups: dict[str, str] | None = None,
|
||||
list_vars: dict[str, str] | None = None,
|
||||
list_commands_return_value: dict[str, str] | None = None,
|
||||
list_commands_side_effect=None,
|
||||
run_command: MagicMock = None,
|
||||
run_command: MagicMock | None = None,
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the nut integration in Home Assistant."""
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ async def setup_integration(
|
|||
aioclient_mock: AiohttpClientMocker,
|
||||
url: str = URL,
|
||||
api_key: str = API_KEY,
|
||||
unique_id: str = None,
|
||||
unique_id: str | None = None,
|
||||
skip_entry_setup: bool = False,
|
||||
connection_error: bool = False,
|
||||
invalid_auth: bool = False,
|
||||
|
|
|
@ -109,7 +109,7 @@ async def async_wait_recording_done(hass: HomeAssistant) -> None:
|
|||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def async_wait_purge_done(hass: HomeAssistant, max: int = None) -> None:
|
||||
async def async_wait_purge_done(hass: HomeAssistant, max: int | None = None) -> None:
|
||||
"""Wait for max number of purge events.
|
||||
|
||||
Because a purge may insert another PurgeTask into
|
||||
|
|
|
@ -111,7 +111,7 @@ class RuckusAjaxApiPatchContext:
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
login_mock: AsyncMock = None,
|
||||
login_mock: AsyncMock | None = None,
|
||||
system_info: dict | None = None,
|
||||
mesh_info: dict | None = None,
|
||||
active_clients: list[dict] | AsyncMock | None = None,
|
||||
|
|
|
@ -61,7 +61,7 @@ async def stub_async_connect(
|
|||
gtype=None,
|
||||
gsubtype=None,
|
||||
name=MOCK_ADAPTER_NAME,
|
||||
connection_closed_callback: Callable = None,
|
||||
connection_closed_callback: Callable | None = None,
|
||||
) -> bool:
|
||||
"""Initialize minimum attributes needed for tests."""
|
||||
self._ip = ip
|
||||
|
|
|
@ -32,7 +32,7 @@ def signal_requests_mock_factory(requests_mock: Mocker) -> Mocker:
|
|||
"""Create signal service mock from factory."""
|
||||
|
||||
def _signal_requests_mock_factory(
|
||||
success_send_result: bool = True, content_length_header: str = None
|
||||
success_send_result: bool = True, content_length_header: str | None = None
|
||||
) -> Mocker:
|
||||
requests_mock.register_uri(
|
||||
"GET",
|
||||
|
|
|
@ -253,7 +253,7 @@ def device_factory_fixture():
|
|||
api = Mock(Api)
|
||||
api.post_device_command.return_value = {"results": [{"status": "ACCEPTED"}]}
|
||||
|
||||
def _factory(label, capabilities, status: dict = None):
|
||||
def _factory(label, capabilities, status: dict | None = None):
|
||||
device_data = {
|
||||
"deviceId": str(uuid4()),
|
||||
"name": "Device Type Handler Name",
|
||||
|
|
|
@ -262,7 +262,7 @@ YAML_CONFIG_ALL_TEMPLATES = {
|
|||
|
||||
async def init_integration(
|
||||
hass: HomeAssistant,
|
||||
config: dict[str, Any] = None,
|
||||
config: dict[str, Any] | None = None,
|
||||
entry_id: str = "1",
|
||||
source: str = SOURCE_USER,
|
||||
) -> MockConfigEntry:
|
||||
|
|
|
@ -72,7 +72,7 @@ async def setup_integration(
|
|||
aioclient_mock: AiohttpClientMocker,
|
||||
url: str = URL,
|
||||
api_key: str = API_KEY,
|
||||
unique_id: str = None,
|
||||
unique_id: str | None = None,
|
||||
skip_entry_setup: bool = False,
|
||||
invalid_auth: bool = False,
|
||||
) -> MockConfigEntry:
|
||||
|
|
|
@ -54,7 +54,7 @@ class MockValveEntity(ValveEntity):
|
|||
unique_id: str = "mock_valve",
|
||||
name: str = "Valve",
|
||||
features: ValveEntityFeature = ValveEntityFeature(0),
|
||||
current_position: int = None,
|
||||
current_position: int | None = None,
|
||||
device_class: ValveDeviceClass = None,
|
||||
reports_position: bool = True,
|
||||
) -> None:
|
||||
|
@ -104,7 +104,7 @@ class MockBinaryValveEntity(ValveEntity):
|
|||
unique_id: str = "mock_valve_2",
|
||||
name: str = "Valve",
|
||||
features: ValveEntityFeature = ValveEntityFeature(0),
|
||||
is_closed: bool = None,
|
||||
is_closed: bool | None = None,
|
||||
) -> None:
|
||||
"""Initialize the valve."""
|
||||
self._attr_name = name
|
||||
|
|
|
@ -58,8 +58,8 @@ class ControllerConfig(NamedTuple):
|
|||
|
||||
|
||||
def new_simple_controller_config(
|
||||
config: dict = None,
|
||||
options: dict = None,
|
||||
config: dict | None = None,
|
||||
options: dict | None = None,
|
||||
config_source=ConfigSource.CONFIG_FLOW,
|
||||
serial_number="1111",
|
||||
devices: tuple[pv.VeraDevice, ...] = (),
|
||||
|
|
|
@ -20,8 +20,8 @@ async def run_sensor_test(
|
|||
category: int,
|
||||
class_property: str,
|
||||
assert_states: tuple[tuple[Any, Any]],
|
||||
assert_unit_of_measurement: str = None,
|
||||
setup_callback: Callable[[pv.VeraController], None] = None,
|
||||
assert_unit_of_measurement: str | None = None,
|
||||
setup_callback: Callable[[pv.VeraController], None] | None = None,
|
||||
) -> None:
|
||||
"""Test generic sensor."""
|
||||
vera_device: pv.VeraSensor = MagicMock(spec=pv.VeraSensor)
|
||||
|
|
|
@ -43,7 +43,7 @@ async def mock_get_version_update(
|
|||
freezer: FrozenDateTimeFactory,
|
||||
version: str = MOCK_VERSION,
|
||||
data: dict[str, Any] = MOCK_VERSION_DATA,
|
||||
side_effect: Exception = None,
|
||||
side_effect: Exception | None = None,
|
||||
) -> None:
|
||||
"""Mock getting version."""
|
||||
with patch(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue