mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 09:39:42 +00:00
[core] Enable ruff C4 (flake8-comprehensions) lint family (#16653)
This commit is contained in:
@@ -563,13 +563,13 @@ async def to_code(config):
|
||||
point_set.update(flatten(config[CONF_GLYPHS]))
|
||||
# Create the codepoint to font file map
|
||||
base_font = FONT_CACHE[config[CONF_FILE]]
|
||||
point_font_map: dict[str, Face] = {c: base_font for c in point_set}
|
||||
point_font_map: dict[str, Face] = dict.fromkeys(point_set, base_font)
|
||||
# process extras, updating the map and extending the codepoint list
|
||||
for extra in config[CONF_EXTRAS]:
|
||||
extra_points = flatten(extra[CONF_GLYPHS])
|
||||
point_set.update(extra_points)
|
||||
extra_font = FONT_CACHE[extra[CONF_FILE]]
|
||||
point_font_map.update({c: extra_font for c in extra_points})
|
||||
point_font_map.update(dict.fromkeys(extra_points, extra_font))
|
||||
|
||||
codepoints = list(point_set)
|
||||
codepoints.sort(key=functools.cmp_to_key(glyph_comparator))
|
||||
|
||||
@@ -513,13 +513,13 @@ async def component_to_code(config):
|
||||
|
||||
# apply LibreTiny options from framework: block
|
||||
# setup LT logger to work nicely with ESPHome logger
|
||||
lt_options = dict(
|
||||
LT_LOGLEVEL="LT_LEVEL_" + framework[CONF_LOGLEVEL],
|
||||
LT_LOGGER_CALLER=0,
|
||||
LT_LOGGER_TASK=0,
|
||||
LT_LOGGER_COLOR=1,
|
||||
LT_USE_TIME=1,
|
||||
)
|
||||
lt_options = {
|
||||
"LT_LOGLEVEL": "LT_LEVEL_" + framework[CONF_LOGLEVEL],
|
||||
"LT_LOGGER_CALLER": 0,
|
||||
"LT_LOGGER_TASK": 0,
|
||||
"LT_LOGGER_COLOR": 1,
|
||||
"LT_USE_TIME": 1,
|
||||
}
|
||||
# enable/disable per-module debugging
|
||||
for module in framework[CONF_DEBUG]:
|
||||
if module == "NONE":
|
||||
|
||||
@@ -174,7 +174,7 @@ def generate_lv_conf_h():
|
||||
if clashes:
|
||||
LOGGER.warning(
|
||||
"Some defines are set both by ESPHome build flags and by LVGL configuration which may lead to unexpected behavior: %s",
|
||||
sorted(list(clashes)),
|
||||
sorted(clashes),
|
||||
)
|
||||
unused_defines = all_defines - lv_defines.keys() - defines_from_flags
|
||||
|
||||
|
||||
@@ -335,7 +335,7 @@ TYPE_NONE = "none"
|
||||
|
||||
DIRECTIONS = LvConstant("LV_DIR_", "LEFT", "RIGHT", "BOTTOM", "TOP")
|
||||
|
||||
LV_FONTS = list(f"montserrat_{s}" for s in range(8, 50, 2)) + [
|
||||
LV_FONTS = [f"montserrat_{s}" for s in range(8, 50, 2)] + [
|
||||
"dejavu_16_persian_hebrew",
|
||||
"simsun_16_cjk",
|
||||
"unscii_8",
|
||||
|
||||
@@ -16,7 +16,7 @@ def define_has_component(component_type: str, keys: list[str]) -> None:
|
||||
cg.add_define(
|
||||
f"OPENTHERM_{component_type.upper()}_LIST(F, sep)",
|
||||
cg.RawExpression(
|
||||
" sep ".join(map(lambda key: f"F({key}_{component_type.lower()})", keys))
|
||||
" sep ".join(f"F({key}_{component_type.lower()})" for key in keys)
|
||||
),
|
||||
)
|
||||
for key in keys:
|
||||
@@ -30,12 +30,8 @@ def define_has_settings(keys: list[str], schemas: dict[str, SettingSchema]) -> N
|
||||
"OPENTHERM_SETTING_LIST(F, sep)",
|
||||
cg.RawExpression(
|
||||
" sep ".join(
|
||||
map(
|
||||
lambda key: (
|
||||
f"F({schemas[key].backing_type}, {key}_setting, {schemas[key].default_value})"
|
||||
),
|
||||
keys,
|
||||
)
|
||||
f"F({schemas[key].backing_type}, {key}_setting, {schemas[key].default_value})"
|
||||
for key in keys
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
@@ -204,7 +204,7 @@ def cron_expression_validator(name, min_value, max_value, special_mapping=None):
|
||||
raise cv.Invalid(
|
||||
f"{name} {v} is out of range (min={min_value} max={max_value})."
|
||||
)
|
||||
return list(sorted(value))
|
||||
return sorted(value)
|
||||
value = cv.string(value)
|
||||
values = set()
|
||||
for part in value.split(","):
|
||||
|
||||
@@ -40,7 +40,7 @@ def _str_to_lst_of_str(a: str | list[str]) -> list[str]:
|
||||
"""
|
||||
if isinstance(a, list):
|
||||
return a
|
||||
return list(f.strip() for f in a.split(";") if f.strip())
|
||||
return [f.strip() for f in a.split(";") if f.strip()]
|
||||
|
||||
|
||||
ESPHOME_STAMP_FILE = ".esphome.stamp.json"
|
||||
|
||||
@@ -313,9 +313,7 @@ def gpio_base_schema(
|
||||
:return: A schema for the pin
|
||||
"""
|
||||
mode_default = len(modes) == 1
|
||||
mode_dict = dict(
|
||||
map(lambda m: (cv.Optional(m, default=mode_default), cv.boolean), modes)
|
||||
)
|
||||
mode_dict = {cv.Optional(m, default=mode_default): cv.boolean for m in modes}
|
||||
|
||||
def _number_validator(value):
|
||||
if isinstance(value, str) and value.upper().startswith("GPIOX"):
|
||||
|
||||
@@ -111,6 +111,7 @@ exclude = ['generated']
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = [
|
||||
"C4", # flake8-comprehensions
|
||||
"E", # pycodestyle
|
||||
"EXE", # flake8-executable
|
||||
"F", # pyflakes/autoflake
|
||||
|
||||
@@ -341,7 +341,7 @@ def lint_const_ordered(fname, content):
|
||||
matching = [
|
||||
(i + 1, line) for i, line in enumerate(lines) if line.startswith(start)
|
||||
]
|
||||
ordered = list(sorted(matching, key=lambda x: x[1].replace("_", " ")))
|
||||
ordered = sorted(matching, key=lambda x: x[1].replace("_", " "))
|
||||
ordered = [(mi, ol) for (mi, _), (_, ol) in zip(matching, ordered)]
|
||||
for (mi, mline), (_, ol) in zip(matching, ordered):
|
||||
if mline == ol:
|
||||
|
||||
@@ -12,9 +12,9 @@ if __name__ == "__main__":
|
||||
components = get_components_with_dependencies(files, True)
|
||||
|
||||
dump = {
|
||||
"actions": sorted(list(ACTION_REGISTRY.keys())),
|
||||
"conditions": sorted(list(CONDITION_REGISTRY.keys())),
|
||||
"pin_providers": sorted(list(PIN_SCHEMA_REGISTRY.keys())),
|
||||
"actions": sorted(ACTION_REGISTRY.keys()),
|
||||
"conditions": sorted(CONDITION_REGISTRY.keys()),
|
||||
"pin_providers": sorted(PIN_SCHEMA_REGISTRY.keys()),
|
||||
}
|
||||
|
||||
print(json.dumps(dump, indent=2))
|
||||
|
||||
Reference in New Issue
Block a user