Skip to content

Commit

Permalink
Add flake8 comprehensions checks to pre-commit & CI (home-assistant#4…
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Mar 19, 2021
1 parent fa5ce70 commit 8a56dbf
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 29 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ repos:
# default yet due to https://github.com/plinss/flake8-noqa/issues/1
# - flake8-noqa==1.1.0
- pydocstyle==5.1.1
- flake8-comprehensions==3.4.0
files: ^(homeassistant|script|tests)/.+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.0
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/denon/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def is_volume_muted(self):
@property
def source_list(self):
"""Return the list of available input sources."""
return sorted(list(self._source_list))
return sorted(self._source_list)

@property
def media_title(self):
Expand Down
8 changes: 3 additions & 5 deletions homeassistant/components/emulated_hue/hue_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,9 @@ async def put(self, request, username, entity_number):
return self.json_message("Bad request", HTTP_BAD_REQUEST)
if HUE_API_STATE_XY in request_json:
try:
parsed[STATE_XY] = tuple(
(
float(request_json[HUE_API_STATE_XY][0]),
float(request_json[HUE_API_STATE_XY][1]),
)
parsed[STATE_XY] = (
float(request_json[HUE_API_STATE_XY][0]),
float(request_json[HUE_API_STATE_XY][1]),
)
except ValueError:
_LOGGER.error("Unable to parse data (2): %s", request_json)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/flux_led/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
TRANSITION_JUMP = "jump"
TRANSITION_STROBE = "strobe"

FLUX_EFFECT_LIST = sorted(list(EFFECT_MAP)) + [EFFECT_RANDOM]
FLUX_EFFECT_LIST = sorted(EFFECT_MAP) + [EFFECT_RANDOM]

CUSTOM_EFFECT_SCHEMA = vol.Schema(
{
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/light/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def capability_attributes(self):
data[ATTR_EFFECT_LIST] = self.effect_list

data[ATTR_SUPPORTED_COLOR_MODES] = sorted(
list(self._light_internal_supported_color_modes)
self._light_internal_supported_color_modes
)

return data
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/nad/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def source(self):
@property
def source_list(self):
"""List of available input sources."""
return sorted(list(self._reverse_mapping))
return sorted(self._reverse_mapping)

@property
def available(self):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/sms/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def sms_callback(self, state_machine, callback_type, callback_data):
)
entries = self.get_and_delete_all_sms(state_machine)
_LOGGER.debug("SMS entries:%s", entries)
data = list()
data = []

for entry in entries:
decoded_entry = gammu.DecodeSMS(entry)
Expand Down Expand Up @@ -78,7 +78,7 @@ def get_and_delete_all_sms(self, state_machine, force=False):
start_remaining = remaining
# Get all sms
start = True
entries = list()
entries = []
all_parts = -1
all_parts_arrived = False
_LOGGER.debug("Start remaining:%i", start_remaining)
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/uk_transport/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@

_QUERY_SCHEME = vol.Schema(
{
vol.Required(CONF_MODE): vol.All(
cv.ensure_list, [vol.In(list(["bus", "train"]))]
),
vol.Required(CONF_MODE): vol.All(cv.ensure_list, [vol.In(["bus", "train"])]),
vol.Required(CONF_ORIGIN): cv.string,
vol.Required(CONF_DESTINATION): cv.string,
}
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/unifi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ async def async_step_device_tracker(self, user_input=None):
if "name" in wlan
}
)
ssid_filter = {ssid: ssid for ssid in sorted(list(ssids))}
ssid_filter = {ssid: ssid for ssid in sorted(ssids)}

return self.async_show_form(
step_id="device_tracker",
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/webostv/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def source(self):
@property
def source_list(self):
"""List of available input sources."""
return sorted(list(self._source_list))
return sorted(self._source_list)

@property
def media_content_type(self):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/util/dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def parse_time_expression(parameter: Any, min_value: int, max_value: int) -> lis
elif not hasattr(parameter, "__iter__"):
res = [int(parameter)]
else:
res = list(sorted(int(x) for x in parameter))
res = sorted(int(x) for x in parameter)

for val in res:
if val < min_value or val > max_value:
Expand Down
1 change: 1 addition & 0 deletions requirements_test_pre_commit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
bandit==1.7.0
black==20.8b1
codespell==2.0.0
flake8-comprehensions==3.4.0
flake8-docstrings==1.5.0
flake8==3.8.4
isort==5.7.0
Expand Down
2 changes: 1 addition & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ def add_to_manager(self, manager):
def patch_yaml_files(files_dict, endswith=True):
"""Patch load_yaml with a dictionary of yaml files."""
# match using endswith, start search with longest string
matchlist = sorted(list(files_dict.keys()), key=len) if endswith else []
matchlist = sorted(files_dict.keys(), key=len) if endswith else []

def mock_open_f(fname, **_):
"""Mock open() in the yaml module, used by load_yaml."""
Expand Down
2 changes: 1 addition & 1 deletion tests/components/automation/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_json_encoder(hass):

# Test serializing a set()
data = {"milk", "beer"}
assert sorted(ha_json_enc.default(data)) == sorted(list(data))
assert sorted(ha_json_enc.default(data)) == sorted(data)

# Test serializong object which implements as_dict
assert ha_json_enc.default(state) == state.as_dict()
Expand Down
2 changes: 1 addition & 1 deletion tests/components/group/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ async def test_service_group_set_group_remove_group(hass):
assert group_state.attributes[group.ATTR_AUTO]
assert group_state.attributes["friendly_name"] == "Test2"
assert group_state.attributes["icon"] == "mdi:camera"
assert sorted(list(group_state.attributes["entity_id"])) == sorted(
assert sorted(group_state.attributes["entity_id"]) == sorted(
["test.entity_bla1", "test.entity_id2"]
)

Expand Down
8 changes: 4 additions & 4 deletions tests/components/zwave/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ async def test_entity_discovery(

assert values.primary is value_class.primary
assert len(list(values)) == 3
assert sorted(list(values), key=lambda a: id(a)) == sorted(
assert sorted(values, key=lambda a: id(a)) == sorted(
[value_class.primary, None, None], key=lambda a: id(a)
)

Expand All @@ -885,7 +885,7 @@ async def test_entity_discovery(

assert values.secondary is value_class.secondary
assert len(list(values)) == 3
assert sorted(list(values), key=lambda a: id(a)) == sorted(
assert sorted(values, key=lambda a: id(a)) == sorted(
[value_class.primary, value_class.secondary, None], key=lambda a: id(a)
)

Expand All @@ -902,7 +902,7 @@ async def test_entity_discovery(

assert values.optional is value_class.optional
assert len(list(values)) == 3
assert sorted(list(values), key=lambda a: id(a)) == sorted(
assert sorted(values, key=lambda a: id(a)) == sorted(
[value_class.primary, value_class.secondary, value_class.optional],
key=lambda a: id(a),
)
Expand Down Expand Up @@ -961,7 +961,7 @@ async def test_entity_existing_values(
assert values.secondary is value_class.secondary
assert values.optional is value_class.optional
assert len(list(values)) == 3
assert sorted(list(values), key=lambda a: id(a)) == sorted(
assert sorted(values, key=lambda a: id(a)) == sorted(
[value_class.primary, value_class.secondary, value_class.optional],
key=lambda a: id(a),
)
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_json_encoder(hass):

# Test serializing a set()
data = {"milk", "beer"}
assert sorted(ha_json_enc.default(data)) == sorted(list(data))
assert sorted(ha_json_enc.default(data)) == sorted(data)

# Test serializing an object which implements as_dict
assert ha_json_enc.default(state) == state.as_dict()
Expand Down
8 changes: 4 additions & 4 deletions tests/util/test_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ def test_get_age():

def test_parse_time_expression():
"""Test parse_time_expression."""
assert [x for x in range(60)] == dt_util.parse_time_expression("*", 0, 59)
assert [x for x in range(60)] == dt_util.parse_time_expression(None, 0, 59)
assert list(range(60)) == dt_util.parse_time_expression("*", 0, 59)
assert list(range(60)) == dt_util.parse_time_expression(None, 0, 59)

assert [x for x in range(0, 60, 5)] == dt_util.parse_time_expression("/5", 0, 59)
assert list(range(0, 60, 5)) == dt_util.parse_time_expression("/5", 0, 59)

assert [1, 2, 3] == dt_util.parse_time_expression([2, 1, 3], 0, 59)

assert [x for x in range(24)] == dt_util.parse_time_expression("*", 0, 23)
assert list(range(24)) == dt_util.parse_time_expression("*", 0, 23)

assert [42] == dt_util.parse_time_expression(42, 0, 59)
assert [42] == dt_util.parse_time_expression("42", 0, 59)
Expand Down

0 comments on commit 8a56dbf

Please sign in to comment.