Enable first batch of Ruff RET rules (#114480)
* Enable first batch of Ruff RET rules * disable pylint rules
This commit is contained in:
parent
6e3e09f2c3
commit
d846676e84
10 changed files with 35 additions and 42 deletions
|
@ -304,6 +304,10 @@ disable = [
|
||||||
"use-list-literal", # C405
|
"use-list-literal", # C405
|
||||||
"useless-object-inheritance", # UP004
|
"useless-object-inheritance", # UP004
|
||||||
"useless-return", # PLR1711
|
"useless-return", # PLR1711
|
||||||
|
"no-else-break", # RET508
|
||||||
|
"no-else-continue", # RET507
|
||||||
|
"no-else-raise", # RET506
|
||||||
|
"no-else-return", # RET505
|
||||||
# "no-self-use", # PLR6301 # Optional plugin, not enabled
|
# "no-self-use", # PLR6301 # Optional plugin, not enabled
|
||||||
|
|
||||||
# Handled by mypy
|
# Handled by mypy
|
||||||
|
@ -633,6 +637,7 @@ select = [
|
||||||
"PIE", # flake8-pie
|
"PIE", # flake8-pie
|
||||||
"PL", # pylint
|
"PL", # pylint
|
||||||
"PT", # flake8-pytest-style
|
"PT", # flake8-pytest-style
|
||||||
|
"RET", # flake8-return
|
||||||
"RSE", # flake8-raise
|
"RSE", # flake8-raise
|
||||||
"RUF005", # Consider iterable unpacking instead of concatenation
|
"RUF005", # Consider iterable unpacking instead of concatenation
|
||||||
"RUF006", # Store a reference to the return value of asyncio.create_task
|
"RUF006", # Store a reference to the return value of asyncio.create_task
|
||||||
|
@ -713,6 +718,10 @@ ignore = [
|
||||||
|
|
||||||
# temporarily disabled
|
# temporarily disabled
|
||||||
"PT019",
|
"PT019",
|
||||||
|
"RET504",
|
||||||
|
"RET503",
|
||||||
|
"RET502",
|
||||||
|
"RET501",
|
||||||
"TRY002",
|
"TRY002",
|
||||||
"TRY301"
|
"TRY301"
|
||||||
]
|
]
|
||||||
|
|
|
@ -43,7 +43,7 @@ def flatten_translations(translations):
|
||||||
if isinstance(v, dict):
|
if isinstance(v, dict):
|
||||||
stack.append(iter(v.items()))
|
stack.append(iter(v.items()))
|
||||||
break
|
break
|
||||||
elif isinstance(v, str):
|
if isinstance(v, str):
|
||||||
common_key = "::".join(key_stack)
|
common_key = "::".join(key_stack)
|
||||||
flattened_translations[common_key] = v
|
flattened_translations[common_key] = v
|
||||||
key_stack.pop()
|
key_stack.pop()
|
||||||
|
|
|
@ -32,7 +32,6 @@ class MockSW16Client:
|
||||||
if self.disconnect_callback:
|
if self.disconnect_callback:
|
||||||
self.disconnect_callback()
|
self.disconnect_callback()
|
||||||
return await self.active_transaction
|
return await self.active_transaction
|
||||||
else:
|
|
||||||
self.active_transaction.set_result(True)
|
self.active_transaction.set_result(True)
|
||||||
return self.active_transaction
|
return self.active_transaction
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,8 @@ def entities_fixture(
|
||||||
"""Set up the test environment."""
|
"""Set up the test environment."""
|
||||||
if request.param == "entities_unique_id":
|
if request.param == "entities_unique_id":
|
||||||
return entities_unique_id(entity_registry)
|
return entities_unique_id(entity_registry)
|
||||||
elif request.param == "entities_no_unique_id":
|
if request.param == "entities_no_unique_id":
|
||||||
return entities_no_unique_id(hass)
|
return entities_no_unique_id(hass)
|
||||||
else:
|
|
||||||
raise RuntimeError("Invalid setup fixture")
|
raise RuntimeError("Invalid setup fixture")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,6 @@ def get_kodi_connection(
|
||||||
"""Get Kodi connection."""
|
"""Get Kodi connection."""
|
||||||
if ws_port is None:
|
if ws_port is None:
|
||||||
return MockConnection()
|
return MockConnection()
|
||||||
else:
|
|
||||||
return MockWSConnection()
|
return MockWSConnection()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -84,13 +84,11 @@ class _MockAsyncClient(AsyncClient):
|
||||||
return RoomResolveAliasResponse(
|
return RoomResolveAliasResponse(
|
||||||
room_alias=room_alias, room_id=room_id, servers=[TEST_HOMESERVER]
|
room_alias=room_alias, room_id=room_id, servers=[TEST_HOMESERVER]
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
return RoomResolveAliasError(message=f"Could not resolve {room_alias}")
|
return RoomResolveAliasError(message=f"Could not resolve {room_alias}")
|
||||||
|
|
||||||
async def join(self, room_id: RoomID):
|
async def join(self, room_id: RoomID):
|
||||||
if room_id in TEST_JOINABLE_ROOMS.values():
|
if room_id in TEST_JOINABLE_ROOMS.values():
|
||||||
return JoinResponse(room_id=room_id)
|
return JoinResponse(room_id=room_id)
|
||||||
else:
|
|
||||||
return JoinError(message="Not allowed to join this room.")
|
return JoinError(message="Not allowed to join this room.")
|
||||||
|
|
||||||
async def login(self, *args, **kwargs):
|
async def login(self, *args, **kwargs):
|
||||||
|
@ -101,7 +99,6 @@ class _MockAsyncClient(AsyncClient):
|
||||||
device_id="test_device",
|
device_id="test_device",
|
||||||
user_id=TEST_MXID,
|
user_id=TEST_MXID,
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
self.access_token = ""
|
self.access_token = ""
|
||||||
return LoginError(message="LoginError", status_code="status_code")
|
return LoginError(message="LoginError", status_code="status_code")
|
||||||
|
|
||||||
|
@ -115,7 +112,6 @@ class _MockAsyncClient(AsyncClient):
|
||||||
return WhoamiResponse(
|
return WhoamiResponse(
|
||||||
user_id=TEST_MXID, device_id=TEST_DEVICE_ID, is_guest=False
|
user_id=TEST_MXID, device_id=TEST_DEVICE_ID, is_guest=False
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
self.access_token = ""
|
self.access_token = ""
|
||||||
return WhoamiError(
|
return WhoamiError(
|
||||||
message="Invalid access token passed.", status_code="M_UNKNOWN_TOKEN"
|
message="Invalid access token passed.", status_code="M_UNKNOWN_TOKEN"
|
||||||
|
@ -126,7 +122,6 @@ class _MockAsyncClient(AsyncClient):
|
||||||
raise LocalProtocolError
|
raise LocalProtocolError
|
||||||
if kwargs["room_id"] not in TEST_JOINABLE_ROOMS.values():
|
if kwargs["room_id"] not in TEST_JOINABLE_ROOMS.values():
|
||||||
return ErrorResponse(message="Cannot send a message in this room.")
|
return ErrorResponse(message="Cannot send a message in this room.")
|
||||||
else:
|
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
async def sync(self, *args, **kwargs):
|
async def sync(self, *args, **kwargs):
|
||||||
|
|
|
@ -57,7 +57,6 @@ async def mock_rflink(
|
||||||
|
|
||||||
if fail:
|
if fail:
|
||||||
raise ConnectionRefusedError
|
raise ConnectionRefusedError
|
||||||
else:
|
|
||||||
return transport, protocol
|
return transport, protocol
|
||||||
|
|
||||||
mock_create = Mock(wraps=create_rflink_connection)
|
mock_create = Mock(wraps=create_rflink_connection)
|
||||||
|
|
|
@ -75,14 +75,13 @@ def call_api_side_effect__no_devices(*args, **kwargs):
|
||||||
"""Build a side_effects method for the Helpers.call_api method."""
|
"""Build a side_effects method for the Helpers.call_api method."""
|
||||||
if args[0] == "/cloud/v1/user/login" and args[1] == "post":
|
if args[0] == "/cloud/v1/user/login" and args[1] == "post":
|
||||||
return json.loads(load_fixture("vesync_api_call__login.json", "vesync")), 200
|
return json.loads(load_fixture("vesync_api_call__login.json", "vesync")), 200
|
||||||
elif args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post":
|
if args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post":
|
||||||
return (
|
return (
|
||||||
json.loads(
|
json.loads(
|
||||||
load_fixture("vesync_api_call__devices__no_devices.json", "vesync")
|
load_fixture("vesync_api_call__devices__no_devices.json", "vesync")
|
||||||
),
|
),
|
||||||
200,
|
200,
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}")
|
raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}")
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,7 +89,7 @@ def call_api_side_effect__single_humidifier(*args, **kwargs):
|
||||||
"""Build a side_effects method for the Helpers.call_api method."""
|
"""Build a side_effects method for the Helpers.call_api method."""
|
||||||
if args[0] == "/cloud/v1/user/login" and args[1] == "post":
|
if args[0] == "/cloud/v1/user/login" and args[1] == "post":
|
||||||
return json.loads(load_fixture("vesync_api_call__login.json", "vesync")), 200
|
return json.loads(load_fixture("vesync_api_call__login.json", "vesync")), 200
|
||||||
elif args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post":
|
if args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post":
|
||||||
return (
|
return (
|
||||||
json.loads(
|
json.loads(
|
||||||
load_fixture(
|
load_fixture(
|
||||||
|
@ -99,7 +98,7 @@ def call_api_side_effect__single_humidifier(*args, **kwargs):
|
||||||
),
|
),
|
||||||
200,
|
200,
|
||||||
)
|
)
|
||||||
elif args[0] == "/cloud/v2/deviceManaged/bypassV2" and kwargs["method"] == "post":
|
if args[0] == "/cloud/v2/deviceManaged/bypassV2" and kwargs["method"] == "post":
|
||||||
return (
|
return (
|
||||||
json.loads(
|
json.loads(
|
||||||
load_fixture(
|
load_fixture(
|
||||||
|
@ -108,7 +107,6 @@ def call_api_side_effect__single_humidifier(*args, **kwargs):
|
||||||
),
|
),
|
||||||
200,
|
200,
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}")
|
raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}")
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,14 +114,14 @@ def call_api_side_effect__single_fan(*args, **kwargs):
|
||||||
"""Build a side_effects method for the Helpers.call_api method."""
|
"""Build a side_effects method for the Helpers.call_api method."""
|
||||||
if args[0] == "/cloud/v1/user/login" and args[1] == "post":
|
if args[0] == "/cloud/v1/user/login" and args[1] == "post":
|
||||||
return json.loads(load_fixture("vesync_api_call__login.json", "vesync")), 200
|
return json.loads(load_fixture("vesync_api_call__login.json", "vesync")), 200
|
||||||
elif args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post":
|
if args[0] == "/cloud/v1/deviceManaged/devices" and args[1] == "post":
|
||||||
return (
|
return (
|
||||||
json.loads(
|
json.loads(
|
||||||
load_fixture("vesync_api_call__devices__single_fan.json", "vesync")
|
load_fixture("vesync_api_call__devices__single_fan.json", "vesync")
|
||||||
),
|
),
|
||||||
200,
|
200,
|
||||||
)
|
)
|
||||||
elif (
|
if (
|
||||||
args[0] == "/131airPurifier/v1/device/deviceDetail"
|
args[0] == "/131airPurifier/v1/device/deviceDetail"
|
||||||
and kwargs["method"] == "post"
|
and kwargs["method"] == "post"
|
||||||
):
|
):
|
||||||
|
@ -135,5 +133,4 @@ def call_api_side_effect__single_fan(*args, **kwargs):
|
||||||
),
|
),
|
||||||
200,
|
200,
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}")
|
raise ValueError(f"Unhandled API call args={args}, kwargs={kwargs}")
|
||||||
|
|
|
@ -244,10 +244,7 @@ def patch_zha_config(component: str, overrides: dict[tuple[str, str], Any]):
|
||||||
def new_get_config(config_entry, section, config_key, default):
|
def new_get_config(config_entry, section, config_key, default):
|
||||||
if (section, config_key) in overrides:
|
if (section, config_key) in overrides:
|
||||||
return overrides[section, config_key]
|
return overrides[section, config_key]
|
||||||
else:
|
return async_get_zha_config_value(config_entry, section, config_key, default)
|
||||||
return async_get_zha_config_value(
|
|
||||||
config_entry, section, config_key, default
|
|
||||||
)
|
|
||||||
|
|
||||||
return patch(
|
return patch(
|
||||||
f"homeassistant.components.zha.{component}.async_get_zha_config_value",
|
f"homeassistant.components.zha.{component}.async_get_zha_config_value",
|
||||||
|
|
|
@ -269,7 +269,6 @@ async def test_finish_callback_change_result_type(hass: HomeAssistant) -> None:
|
||||||
return flow.async_show_form(
|
return flow.async_show_form(
|
||||||
step_id="init", data_schema=vol.Schema({"count": int})
|
step_id="init", data_schema=vol.Schema({"count": int})
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
result["result"] = result["data"]["count"]
|
result["result"] = result["data"]["count"]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue