From 545b888034966f45127477bed5a9cf2fa08a9730 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 6 Feb 2024 15:41:34 +0100 Subject: [PATCH] Update ruff to 0.2.1 (#109796) * Update ruff to 0.2.1 * Rename config sections * Update remapped error codes * Add ignores --- .pre-commit-config.yaml | 2 +- homeassistant/components/ring/coordinator.py | 2 +- homeassistant/components/sensor/recorder.py | 3 ++- pylint/ruff.toml | 4 ++-- pyproject.toml | 21 ++++++++++---------- requirements_test_pre_commit.txt | 2 +- script/ruff.toml | 4 ++-- tests/ruff.toml | 6 ++++-- 8 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cc3be5c2391..4b96b5ee2aa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.15 + rev: v0.2.1 hooks: - id: ruff args: diff --git a/homeassistant/components/ring/coordinator.py b/homeassistant/components/ring/coordinator.py index 636d8eb069f..943b1c628bf 100644 --- a/homeassistant/components/ring/coordinator.py +++ b/homeassistant/components/ring/coordinator.py @@ -96,7 +96,7 @@ class RingDataCoordinator(DataUpdateCoordinator[dict[int, RingDeviceData]]): if history_task: data[device.id].history = history_task.result() except ExceptionGroup as eg: - raise eg.exceptions[0] + raise eg.exceptions[0] # noqa: B904 return data diff --git a/homeassistant/components/sensor/recorder.py b/homeassistant/components/sensor/recorder.py index ebf138d39e6..a53ae906718 100644 --- a/homeassistant/components/sensor/recorder.py +++ b/homeassistant/components/sensor/recorder.py @@ -148,7 +148,8 @@ def _equivalent_units(units: set[str | None]) -> bool: if len(units) == 1: return True units = { - EQUIVALENT_UNITS[unit] if unit in EQUIVALENT_UNITS else unit for unit in units + EQUIVALENT_UNITS[unit] if unit in EQUIVALENT_UNITS else unit # noqa: SIM401 + for unit in units } return len(units) == 1 diff --git a/pylint/ruff.toml b/pylint/ruff.toml index 271881141a9..ebf53daa903 100644 --- a/pylint/ruff.toml +++ b/pylint/ruff.toml @@ -1,7 +1,7 @@ # This extend our general Ruff rules specifically for tests extend = "../pyproject.toml" -[isort] +[lint.isort] known-third-party = [ "pylint", -] \ No newline at end of file +] diff --git a/pyproject.toml b/pyproject.toml index 910670c6caa..be53e50da3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -221,7 +221,7 @@ disable = [ "duplicate-key", # F601 "duplicate-string-formatting-argument", # F "duplicate-value", # F - "eval-used", # PGH001 + "eval-used", # S307 "exec-used", # S102 # "expression-not-assigned", # B018, ruff catches new occurrences, needs more work "f-string-without-interpolation", # F541 @@ -241,7 +241,7 @@ disable = [ "named-expr-without-context", # PLW0131 "nested-min-max", # PLW3301 # "pointless-statement", # B018, ruff catches new occurrences, needs more work - "raise-missing-from", # TRY200 + "raise-missing-from", # B904 # "redefined-builtin", # A001, ruff is way more stricter, needs work "try-except-raise", # TRY302 "unused-argument", # ARG001, we don't use it @@ -569,13 +569,14 @@ filterwarnings = [ "ignore:pkg_resources is deprecated as an API:DeprecationWarning:webrtcvad", ] -[tool.ruff] +[tool.ruff.lint] select = [ "B002", # Python does not support the unary prefix increment "B007", # Loop control variable {name} not used within loop body "B014", # Exception handler with duplicate exception "B023", # Function definition does not bind loop variable {name} "B026", # Star-arg unpacking after a keyword argument is strongly discouraged + "B904", # Use raise from to specify exception cause "C", # complexity "COM818", # Trailing comma on bare tuple prohibited "D", # docstrings @@ -589,7 +590,6 @@ select = [ "N804", # First argument of a class method should be named cls "N805", # First argument of a method should be named self "N815", # Variable {name} in class scope should not be mixedCase - "PGH001", # No builtin eval() allowed "PGH004", # Use specific rule codes when using noqa "PLC0414", # Useless import alias. Import alias does not rename original package. "PLC", # pylint @@ -628,7 +628,6 @@ select = [ "T20", # flake8-print "TID251", # Banned imports "TRY004", # Prefer TypeError exception for invalid type - "TRY200", # Use raise from to specify exception cause "TRY302", # Remove exception handler; error is immediately re-raised "UP", # pyupgrade "W", # pycodestyle @@ -681,7 +680,7 @@ ignore = [ "PLE0605", ] -[tool.ruff.flake8-import-conventions.extend-aliases] +[tool.ruff.lint.flake8-import-conventions.extend-aliases] voluptuous = "vol" "homeassistant.helpers.area_registry" = "ar" "homeassistant.helpers.config_validation" = "cv" @@ -690,14 +689,14 @@ voluptuous = "vol" "homeassistant.helpers.issue_registry" = "ir" "homeassistant.util.dt" = "dt_util" -[tool.ruff.flake8-pytest-style] +[tool.ruff.lint.flake8-pytest-style] fixture-parentheses = false -[tool.ruff.flake8-tidy-imports.banned-api] +[tool.ruff.lint.flake8-tidy-imports.banned-api] "async_timeout".msg = "use asyncio.timeout instead" "pytz".msg = "use zoneinfo instead" -[tool.ruff.isort] +[tool.ruff.lint.isort] force-sort-within-sections = true known-first-party = [ "homeassistant", @@ -705,12 +704,12 @@ known-first-party = [ combine-as-imports = true split-on-trailing-comma = false -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] # Allow for main entry & scripts to write to stdout "homeassistant/__main__.py" = ["T201"] "homeassistant/scripts/*" = ["T201"] "script/*" = ["T20"] -[tool.ruff.mccabe] +[tool.ruff.lint.mccabe] max-complexity = 25 diff --git a/requirements_test_pre_commit.txt b/requirements_test_pre_commit.txt index e12fefa0768..32d3f9e0c8b 100644 --- a/requirements_test_pre_commit.txt +++ b/requirements_test_pre_commit.txt @@ -1,5 +1,5 @@ # Automatically generated from .pre-commit-config.yaml by gen_requirements_all.py, do not edit codespell==2.2.2 -ruff==0.1.15 +ruff==0.2.1 yamllint==1.32.0 diff --git a/script/ruff.toml b/script/ruff.toml index 9d77bf60af9..c32b39022cc 100644 --- a/script/ruff.toml +++ b/script/ruff.toml @@ -1,7 +1,7 @@ # This extend our general Ruff rules specifically for tests extend = "../pyproject.toml" -[isort] +[lint.isort] forced-separate = [ "tests", -] \ No newline at end of file +] diff --git a/tests/ruff.toml b/tests/ruff.toml index 05971ce9a08..76e4feacdd2 100644 --- a/tests/ruff.toml +++ b/tests/ruff.toml @@ -1,6 +1,7 @@ # This extend our general Ruff rules specifically for tests extend = "../pyproject.toml" +[lint] extend-select = [ "PT001", # Use @pytest.fixture without parentheses "PT002", # Configuration for fixture specified via positional args, use kwargs @@ -17,10 +18,11 @@ extend-ignore = [ "PLE", # pylint "PLR", # pylint "PLW", # pylint + "B904", # Use raise from to specify exception cause "N815", # Variable {name} in class scope should not be mixedCase ] -[isort] +[lint.isort] known-first-party = [ "homeassistant", "tests", @@ -34,4 +36,4 @@ known-third-party = [ ] forced-separate = [ "tests", -] \ No newline at end of file +]