[ruff] Enable FURB rules for code modernization (#9896)

This commit is contained in:
J. Nick Koston 2025-07-25 22:54:03 -10:00 committed by GitHub
parent d54db471bd
commit d64e4d3c49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 13 additions and 15 deletions

View File

@ -51,8 +51,7 @@ DISPLAY_ROTATIONS = {
def validate_rotation(value):
value = cv.string(value)
if value.endswith("°"):
value = value[:-1]
value = value.removesuffix("°")
return cv.enum(DISPLAY_ROTATIONS, int=True)(value)

View File

@ -409,7 +409,7 @@ def validate_printf(value):
[cCdiouxXeEfgGaAnpsSZ] # type
)
""" # 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]):
raise cv.Invalid(
f"Found {len(matches)} printf-patterns ({', '.join(matches)}), but {len(value[CONF_ARGS])} args were given!"

View File

@ -33,7 +33,7 @@ def validate_printf(value):
[cCdiouxXeEfgGaAnpsSZ] # type
)
""" # 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]):
raise cv.Invalid(
f"Found {len(matches)} printf-patterns ({', '.join(matches)}), but {len(value[CONF_ARGS])} args were given!"

View File

@ -155,8 +155,7 @@ def _read_audio_file_and_type(file_config):
import puremagic
file_type: str = puremagic.from_string(data)
if file_type.startswith("."):
file_type = file_type[1:]
file_type = file_type.removeprefix(".")
media_file_type = audio.AUDIO_FILE_TYPE_ENUM["NONE"]
if file_type in ("wav"):

View File

@ -27,8 +27,7 @@ SetDecelerationAction = stepper_ns.class_("SetDecelerationAction", automation.Ac
def validate_acceleration(value):
value = cv.string(value)
for suffix in ("steps/s^2", "steps/s*s", "steps/s/s", "steps/ss", "steps/(s*s)"):
if value.endswith(suffix):
value = value[: -len(suffix)]
value = value.removesuffix(suffix)
if value == "inf":
return 1e6
@ -48,8 +47,7 @@ def validate_acceleration(value):
def validate_speed(value):
value = cv.string(value)
for suffix in ("steps/s", "steps/s"):
if value.endswith(suffix):
value = value[: -len(suffix)]
value = value.removesuffix(suffix)
if value == "inf":
return 1e6

View File

@ -771,8 +771,7 @@ class MockObj(Expression):
if attr.startswith("P") and self.op not in ["::", ""]:
attr = attr[1:]
next_op = "->"
if attr.startswith("_"):
attr = attr[1:]
attr = attr.removeprefix("_")
return MockObj(f"{self.base}{self.op}{attr}", next_op)
def __call__(self, *args: SafeExpType) -> "MockObj":

View File

@ -76,7 +76,7 @@ def get_include_text():
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

View File

@ -113,6 +113,7 @@ exclude = ['generated']
select = [
"E", # pycodestyle
"F", # pyflakes/autoflake
"FURB", # refurb
"I", # isort
"PERF", # performance
"PL", # pylint

View File

@ -64,8 +64,10 @@ def main():
for line in lines:
if line.startswith("BOARDS = {"):
f.write("BOARDS = {\n")
for board, info in sorted(boards.items()):
f.write(TEMPLATE % (board, info["name"], info["variant"]))
f.writelines(
TEMPLATE % (board, info["name"], info["variant"])
for board, info in sorted(boards.items())
)
f.write("}\n")
break