From f5b651750c2b6d66165eb12b8437f0c5a6bac012 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 9 Feb 2023 13:41:50 +0100 Subject: [PATCH] Enable Ruff ICN001 (#87775) --- homeassistant/components/opencv/image_processing.py | 4 ++-- homeassistant/components/upnp/__init__.py | 4 ++-- pyproject.toml | 5 +++++ tests/components/homekit/test_config_flow.py | 6 +++--- tests/components/kraken/const.py | 10 +++++----- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/opencv/image_processing.py b/homeassistant/components/opencv/image_processing.py index bef163252fa..7c3a881edf8 100644 --- a/homeassistant/components/opencv/image_processing.py +++ b/homeassistant/components/opencv/image_processing.py @@ -4,7 +4,7 @@ from __future__ import annotations from datetime import timedelta import logging -import numpy +import numpy as np import requests import voluptuous as vol @@ -165,7 +165,7 @@ class OpenCVImageProcessor(ImageProcessingEntity): def process_image(self, image): """Process the image.""" - cv_image = cv2.imdecode(numpy.asarray(bytearray(image)), cv2.IMREAD_UNCHANGED) + cv_image = cv2.imdecode(np.asarray(bytearray(image)), cv2.IMREAD_UNCHANGED) matches = {} total_matches = 0 diff --git a/homeassistant/components/upnp/__init__.py b/homeassistant/components/upnp/__init__.py index 0d4c39e6d3d..ac9fe19f4e7 100644 --- a/homeassistant/components/upnp/__init__.py +++ b/homeassistant/components/upnp/__init__.py @@ -11,7 +11,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady -from homeassistant.helpers import config_validation, device_registry +from homeassistant.helpers import config_validation as cv, device_registry from .const import ( CONFIG_ENTRY_HOST, @@ -33,7 +33,7 @@ NOTIFICATION_TITLE = "UPnP/IGD Setup" PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR] -CONFIG_SCHEMA = config_validation.removed(DOMAIN, raise_if_present=False) +CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False) async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: diff --git a/pyproject.toml b/pyproject.toml index 9acb07aab6f..dda11630118 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -244,6 +244,7 @@ select = [ "D", # docstrings "E", # pycodestyle "F", # pyflakes/autoflake + "ICN001", # import concentions; {name} should be imported as {asname} "PGH004", # Use specific rule codes when using noqa "PLC0414", # Useless import alias. Import alias does not rename original package. "SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass @@ -268,6 +269,10 @@ ignore = [ "E731", # do not assign a lambda expression, use a def ] +[tool.ruff.flake8-import-conventions.extend-aliases] +voluptuous = "vol" +"homeassistant.helpers.config_validation" = "cv" + [tool.ruff.flake8-pytest-style] fixture-parentheses = false diff --git a/tests/components/homekit/test_config_flow.py b/tests/components/homekit/test_config_flow.py index 144a97853c5..ad5ba73d208 100644 --- a/tests/components/homekit/test_config_flow.py +++ b/tests/components/homekit/test_config_flow.py @@ -2,7 +2,7 @@ from unittest.mock import patch import pytest -import voluptuous +import voluptuous as vol from homeassistant import config_entries, data_entry_flow from homeassistant.components.homekit.const import ( @@ -1416,7 +1416,7 @@ async def test_options_flow_exclude_mode_skips_category_entities( # sonos_config_switch.entity_id is a config category entity # so it should not be selectable since it will always be excluded - with pytest.raises(voluptuous.error.MultipleInvalid): + with pytest.raises(vol.error.MultipleInvalid): await hass.config_entries.options.async_configure( result2["flow_id"], user_input={"entities": [sonos_config_switch.entity_id]}, @@ -1506,7 +1506,7 @@ async def test_options_flow_exclude_mode_skips_hidden_entities( # sonos_hidden_switch.entity_id is a hidden entity # so it should not be selectable since it will always be excluded - with pytest.raises(voluptuous.error.MultipleInvalid): + with pytest.raises(vol.error.MultipleInvalid): await hass.config_entries.options.async_configure( result2["flow_id"], user_input={"entities": [sonos_hidden_switch.entity_id]}, diff --git a/tests/components/kraken/const.py b/tests/components/kraken/const.py index 78658ffd660..263618dfd2d 100644 --- a/tests/components/kraken/const.py +++ b/tests/components/kraken/const.py @@ -1,19 +1,19 @@ """Constants for kraken tests.""" -import pandas +import pandas as pd -TRADEABLE_ASSET_PAIR_RESPONSE = pandas.DataFrame( +TRADEABLE_ASSET_PAIR_RESPONSE = pd.DataFrame( {"wsname": ["ADA/XBT", "ADA/ETH", "XBT/EUR", "XBT/GBP", "XBT/USD", "XBT/JPY"]}, columns=["wsname"], index=["ADAXBT", "ADAETH", "XBTEUR", "XXBTZGBP", "XXBTZUSD", "XXBTZJPY"], ) -MISSING_PAIR_TRADEABLE_ASSET_PAIR_RESPONSE = pandas.DataFrame( +MISSING_PAIR_TRADEABLE_ASSET_PAIR_RESPONSE = pd.DataFrame( {"wsname": ["ADA/XBT", "ADA/ETH", "XBT/EUR", "XBT/GBP", "XBT/JPY"]}, columns=["wsname"], index=["ADAXBT", "ADAETH", "XBTEUR", "XXBTZGBP", "XXBTZJPY"], ) -TICKER_INFORMATION_RESPONSE = pandas.DataFrame( +TICKER_INFORMATION_RESPONSE = pd.DataFrame( { "a": [ [0.000349400, 15949, 15949.000], @@ -85,7 +85,7 @@ TICKER_INFORMATION_RESPONSE = pandas.DataFrame( index=["ADAXBT", "ADAETH", "XBTEUR", "XXBTZGBP", "XXBTZUSD", "XXBTZJPY"], ) -MISSING_PAIR_TICKER_INFORMATION_RESPONSE = pandas.DataFrame( +MISSING_PAIR_TICKER_INFORMATION_RESPONSE = pd.DataFrame( { "a": [ [0.000349400, 15949, 15949.000],