mirror of
https://github.com/esphome/esphome.git
synced 2025-07-29 06:36:45 +00:00
[ruff] Enable FURB rules for code modernization (#9896)
This commit is contained in:
parent
d54db471bd
commit
d64e4d3c49
@ -51,8 +51,7 @@ DISPLAY_ROTATIONS = {
|
|||||||
|
|
||||||
def validate_rotation(value):
|
def validate_rotation(value):
|
||||||
value = cv.string(value)
|
value = cv.string(value)
|
||||||
if value.endswith("°"):
|
value = value.removesuffix("°")
|
||||||
value = value[:-1]
|
|
||||||
return cv.enum(DISPLAY_ROTATIONS, int=True)(value)
|
return cv.enum(DISPLAY_ROTATIONS, int=True)(value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -409,7 +409,7 @@ def validate_printf(value):
|
|||||||
[cCdiouxXeEfgGaAnpsSZ] # type
|
[cCdiouxXeEfgGaAnpsSZ] # type
|
||||||
)
|
)
|
||||||
""" # noqa
|
""" # noqa
|
||||||
matches = re.findall(cfmt, value[CONF_FORMAT], flags=re.X)
|
matches = re.findall(cfmt, value[CONF_FORMAT], flags=re.VERBOSE)
|
||||||
if len(matches) != len(value[CONF_ARGS]):
|
if len(matches) != len(value[CONF_ARGS]):
|
||||||
raise cv.Invalid(
|
raise cv.Invalid(
|
||||||
f"Found {len(matches)} printf-patterns ({', '.join(matches)}), but {len(value[CONF_ARGS])} args were given!"
|
f"Found {len(matches)} printf-patterns ({', '.join(matches)}), but {len(value[CONF_ARGS])} args were given!"
|
||||||
|
@ -33,7 +33,7 @@ def validate_printf(value):
|
|||||||
[cCdiouxXeEfgGaAnpsSZ] # type
|
[cCdiouxXeEfgGaAnpsSZ] # type
|
||||||
)
|
)
|
||||||
""" # noqa
|
""" # noqa
|
||||||
matches = re.findall(cfmt, value[CONF_FORMAT], flags=re.X)
|
matches = re.findall(cfmt, value[CONF_FORMAT], flags=re.VERBOSE)
|
||||||
if len(matches) != len(value[CONF_ARGS]):
|
if len(matches) != len(value[CONF_ARGS]):
|
||||||
raise cv.Invalid(
|
raise cv.Invalid(
|
||||||
f"Found {len(matches)} printf-patterns ({', '.join(matches)}), but {len(value[CONF_ARGS])} args were given!"
|
f"Found {len(matches)} printf-patterns ({', '.join(matches)}), but {len(value[CONF_ARGS])} args were given!"
|
||||||
|
@ -155,8 +155,7 @@ def _read_audio_file_and_type(file_config):
|
|||||||
import puremagic
|
import puremagic
|
||||||
|
|
||||||
file_type: str = puremagic.from_string(data)
|
file_type: str = puremagic.from_string(data)
|
||||||
if file_type.startswith("."):
|
file_type = file_type.removeprefix(".")
|
||||||
file_type = file_type[1:]
|
|
||||||
|
|
||||||
media_file_type = audio.AUDIO_FILE_TYPE_ENUM["NONE"]
|
media_file_type = audio.AUDIO_FILE_TYPE_ENUM["NONE"]
|
||||||
if file_type in ("wav"):
|
if file_type in ("wav"):
|
||||||
|
@ -27,8 +27,7 @@ SetDecelerationAction = stepper_ns.class_("SetDecelerationAction", automation.Ac
|
|||||||
def validate_acceleration(value):
|
def validate_acceleration(value):
|
||||||
value = cv.string(value)
|
value = cv.string(value)
|
||||||
for suffix in ("steps/s^2", "steps/s*s", "steps/s/s", "steps/ss", "steps/(s*s)"):
|
for suffix in ("steps/s^2", "steps/s*s", "steps/s/s", "steps/ss", "steps/(s*s)"):
|
||||||
if value.endswith(suffix):
|
value = value.removesuffix(suffix)
|
||||||
value = value[: -len(suffix)]
|
|
||||||
|
|
||||||
if value == "inf":
|
if value == "inf":
|
||||||
return 1e6
|
return 1e6
|
||||||
@ -48,8 +47,7 @@ def validate_acceleration(value):
|
|||||||
def validate_speed(value):
|
def validate_speed(value):
|
||||||
value = cv.string(value)
|
value = cv.string(value)
|
||||||
for suffix in ("steps/s", "steps/s"):
|
for suffix in ("steps/s", "steps/s"):
|
||||||
if value.endswith(suffix):
|
value = value.removesuffix(suffix)
|
||||||
value = value[: -len(suffix)]
|
|
||||||
|
|
||||||
if value == "inf":
|
if value == "inf":
|
||||||
return 1e6
|
return 1e6
|
||||||
|
@ -771,8 +771,7 @@ class MockObj(Expression):
|
|||||||
if attr.startswith("P") and self.op not in ["::", ""]:
|
if attr.startswith("P") and self.op not in ["::", ""]:
|
||||||
attr = attr[1:]
|
attr = attr[1:]
|
||||||
next_op = "->"
|
next_op = "->"
|
||||||
if attr.startswith("_"):
|
attr = attr.removeprefix("_")
|
||||||
attr = attr[1:]
|
|
||||||
return MockObj(f"{self.base}{self.op}{attr}", next_op)
|
return MockObj(f"{self.base}{self.op}{attr}", next_op)
|
||||||
|
|
||||||
def __call__(self, *args: SafeExpType) -> "MockObj":
|
def __call__(self, *args: SafeExpType) -> "MockObj":
|
||||||
|
@ -76,7 +76,7 @@ def get_include_text():
|
|||||||
|
|
||||||
|
|
||||||
def replace_file_content(text, pattern, repl):
|
def replace_file_content(text, pattern, repl):
|
||||||
content_new, count = re.subn(pattern, repl, text, flags=re.M)
|
content_new, count = re.subn(pattern, repl, text, flags=re.MULTILINE)
|
||||||
return content_new, count
|
return content_new, count
|
||||||
|
|
||||||
|
|
||||||
|
@ -113,6 +113,7 @@ exclude = ['generated']
|
|||||||
select = [
|
select = [
|
||||||
"E", # pycodestyle
|
"E", # pycodestyle
|
||||||
"F", # pyflakes/autoflake
|
"F", # pyflakes/autoflake
|
||||||
|
"FURB", # refurb
|
||||||
"I", # isort
|
"I", # isort
|
||||||
"PERF", # performance
|
"PERF", # performance
|
||||||
"PL", # pylint
|
"PL", # pylint
|
||||||
|
@ -64,8 +64,10 @@ def main():
|
|||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith("BOARDS = {"):
|
if line.startswith("BOARDS = {"):
|
||||||
f.write("BOARDS = {\n")
|
f.write("BOARDS = {\n")
|
||||||
for board, info in sorted(boards.items()):
|
f.writelines(
|
||||||
f.write(TEMPLATE % (board, info["name"], info["variant"]))
|
TEMPLATE % (board, info["name"], info["variant"])
|
||||||
|
for board, info in sorted(boards.items())
|
||||||
|
)
|
||||||
f.write("}\n")
|
f.write("}\n")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user