Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ruff to 0.2.1 #109796

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/ring/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def _async_update_data(self):
if history_task:
data[device.id].history = history_task.result()
except ExceptionGroup as eg:
raise eg.exceptions[0]
raise eg.exceptions[0] # noqa: B904
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that in the other PR you had fixed it and put a raise from but in this one you’re suppressing B904. Was there something wrong with the other way or some other reason?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The except here catches an ExceptionGroup, not just a single exception. Adding from eg here would add unhandled errors in a TaskGroup (1 sub-exception)' to the end of the except message. Not sure that makes sense. I'm open to suggestions though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks that makes sense and I don’t have a better suggestion atm.


return data

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/sensor/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pylint/ruff.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This extend our general Ruff rules specifically for tests
extend = "../pyproject.toml"

[isort]
[lint.isort]
known-third-party = [
"pylint",
]
]
21 changes: 10 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -690,27 +689,27 @@ 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",
]
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
2 changes: 1 addition & 1 deletion requirements_test_pre_commit.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions script/ruff.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This extend our general Ruff rules specifically for tests
extend = "../pyproject.toml"

[isort]
[lint.isort]
forced-separate = [
"tests",
]
]
6 changes: 4 additions & 2 deletions tests/ruff.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand All @@ -34,4 +36,4 @@ known-third-party = [
]
forced-separate = [
"tests",
]
]
Loading