diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 29365969725212..de54a5728d3389 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,8 +38,8 @@ repos: - --format=custom - --configfile=tests/bandit.yaml files: ^(homeassistant|script|tests)/.+\.py$ - - repo: https://github.com/pre-commit/mirrors-isort - rev: v4.3.21 + - repo: https://github.com/timothycrosley/isort + rev: 5.4.2 hooks: - id: isort - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/homeassistant/__main__.py b/homeassistant/__main__.py index c229409a8d3206..840e0bed24d5f1 100644 --- a/homeassistant/__main__.py +++ b/homeassistant/__main__.py @@ -195,7 +195,7 @@ def closefds_osx(min_fd: int, max_fd: int) -> None: get rid of. """ # pylint: disable=import-outside-toplevel - from fcntl import fcntl, F_GETFD, F_SETFD, FD_CLOEXEC + from fcntl import F_GETFD, F_SETFD, FD_CLOEXEC, fcntl for _fd in range(min_fd, max_fd): try: diff --git a/homeassistant/auth/permissions/models.py b/homeassistant/auth/permissions/models.py index 435d5f2e9823d5..2542be14cc613d 100644 --- a/homeassistant/auth/permissions/models.py +++ b/homeassistant/auth/permissions/models.py @@ -5,8 +5,10 @@ if TYPE_CHECKING: # pylint: disable=unused-import - from homeassistant.helpers import entity_registry as ent_reg # noqa: F401 - from homeassistant.helpers import device_registry as dev_reg # noqa: F401 + from homeassistant.helpers import ( # noqa: F401 + device_registry as dev_reg, + entity_registry as ent_reg, + ) @attr.s(slots=True) diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index f72cb082671c78..e77d4ef134eb63 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -606,6 +606,7 @@ def _start(self, bridged_states): type_cameras, type_covers, type_fans, + type_humidifiers, type_lights, type_locks, type_media_players, @@ -613,7 +614,6 @@ def _start(self, bridged_states): type_sensors, type_switches, type_thermostats, - type_humidifiers, ) for state in bridged_states: diff --git a/homeassistant/components/huawei_lte/config_flow.py b/homeassistant/components/huawei_lte/config_flow.py index b834f4dab943da..9d5ce40074d3ba 100644 --- a/homeassistant/components/huawei_lte/config_flow.py +++ b/homeassistant/components/huawei_lte/config_flow.py @@ -30,8 +30,9 @@ ) from homeassistant.core import callback -# see https://github.com/PyCQA/pylint/issues/3202 about the DOMAIN's pylint issue from .const import CONNECTION_TIMEOUT, DEFAULT_DEVICE_NAME, DEFAULT_NOTIFY_SERVICE_NAME + +# see https://github.com/PyCQA/pylint/issues/3202 about the DOMAIN's pylint issue from .const import DOMAIN # pylint: disable=unused-import _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/switcher_kis/switch.py b/homeassistant/components/switcher_kis/switch.py index c2254968901379..badab64391ec54 100644 --- a/homeassistant/components/switcher_kis/switch.py +++ b/homeassistant/components/switcher_kis/switch.py @@ -27,8 +27,8 @@ # pylint: disable=ungrouped-imports if TYPE_CHECKING: - from aioswitcher.devices import SwitcherV2Device from aioswitcher.api.messages import SwitcherV2ControlResponseMSG + from aioswitcher.devices import SwitcherV2Device _LOGGER = getLogger(__name__) diff --git a/homeassistant/components/tensorflow/image_processing.py b/homeassistant/components/tensorflow/image_processing.py index d293a19d8d655f..564dd7377b1584 100644 --- a/homeassistant/components/tensorflow/image_processing.py +++ b/homeassistant/components/tensorflow/image_processing.py @@ -125,8 +125,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None): # (The model_dir is created during the manual setup process. See integration docs.) # pylint: disable=import-outside-toplevel - from object_detection.utils import config_util, label_map_util from object_detection.builders import model_builder + from object_detection.utils import config_util, label_map_util except ImportError: _LOGGER.error( "No TensorFlow Object Detection library found! Install or compile " diff --git a/homeassistant/components/zha/core/typing.py b/homeassistant/components/zha/core/typing.py index bce4a058ac62f1..0fe46a4628e2ef 100644 --- a/homeassistant/components/zha/core/typing.py +++ b/homeassistant/components/zha/core/typing.py @@ -26,13 +26,13 @@ ZigpyZdoType = zigpy.zdo.ZDO if TYPE_CHECKING: + import homeassistant.components.zha.core.channels import homeassistant.components.zha.core.channels as channels import homeassistant.components.zha.core.channels.base as base_channels import homeassistant.components.zha.core.device import homeassistant.components.zha.core.gateway import homeassistant.components.zha.core.group import homeassistant.components.zha.entity - import homeassistant.components.zha.core.channels ChannelType = base_channels.ZigbeeChannel ChannelsType = channels.Channels diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index 296271288d2570..d679de7cfbd487 100644 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -335,12 +335,13 @@ async def async_setup_entry(hass, config_entry): Will automatically load components to support devices found on the network. """ - from pydispatch import dispatcher - # pylint: disable=import-error - from openzwave.option import ZWaveOption - from openzwave.network import ZWaveNetwork from openzwave.group import ZWaveGroup + from openzwave.network import ZWaveNetwork + from openzwave.option import ZWaveOption + + # pylint: enable=import-error + from pydispatch import dispatcher # Merge config entry and yaml config config = config_entry.data diff --git a/homeassistant/components/zwave/config_flow.py b/homeassistant/components/zwave/config_flow.py index cff197b7e97813..d6c64e914f6cc5 100644 --- a/homeassistant/components/zwave/config_flow.py +++ b/homeassistant/components/zwave/config_flow.py @@ -43,8 +43,8 @@ async def async_step_user(self, user_input=None): if user_input is not None: # Check if USB path is valid - from openzwave.option import ZWaveOption from openzwave.object import ZWaveException + from openzwave.option import ZWaveOption try: from functools import partial diff --git a/homeassistant/core.py b/homeassistant/core.py index 1540b69b36bd2a..ad083f60574663 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -80,8 +80,8 @@ # Typing imports that create a circular dependency if TYPE_CHECKING: from homeassistant.auth import AuthManager - from homeassistant.config_entries import ConfigEntries from homeassistant.components.http import HomeAssistantHTTP + from homeassistant.config_entries import ConfigEntries block_async_io.enable() diff --git a/requirements_test_pre_commit.txt b/requirements_test_pre_commit.txt index ceca5145010acc..1594fa94990601 100644 --- a/requirements_test_pre_commit.txt +++ b/requirements_test_pre_commit.txt @@ -5,7 +5,7 @@ black==20.8b1 codespell==1.17.1 flake8-docstrings==1.5.0 flake8==3.8.3 -isort==4.3.21 +isort==5.4.2 pydocstyle==5.0.2 pyupgrade==2.7.2 yamllint==1.24.2 diff --git a/script/gen_requirements_all.py b/script/gen_requirements_all.py index e86953a62804ea..27482a0c215865 100755 --- a/script/gen_requirements_all.py +++ b/script/gen_requirements_all.py @@ -8,9 +8,8 @@ import re import sys -from script.hassfest.model import Integration - from homeassistant.util.yaml.loader import load_yaml +from script.hassfest.model import Integration COMMENT_REQUIREMENTS = ( "Adafruit_BBIO", diff --git a/script/hassfest/translations.py b/script/hassfest/translations.py index 801a511211814b..7a9208da7d1459 100644 --- a/script/hassfest/translations.py +++ b/script/hassfest/translations.py @@ -6,12 +6,12 @@ import re from typing import Dict -from script.translations import upload import voluptuous as vol from voluptuous.humanize import humanize_error import homeassistant.helpers.config_validation as cv from homeassistant.util import slugify +from script.translations import upload from .model import Config, Integration diff --git a/setup.cfg b/setup.cfg index 6dace4932dbda7..8dd3e083a8b99a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,19 +38,9 @@ ignore = [isort] # https://github.com/timothycrosley/isort # https://github.com/timothycrosley/isort/wiki/isort-Settings -# splits long import on multiple lines indented by 4 spaces -multi_line_output = 3 -include_trailing_comma=True -force_grid_wrap=0 -use_parentheses=True -line_length=88 -indent = " " -# by default isort don't check module indexes -not_skip = __init__.py +profile = black # will group `import x` and `from x import` of the same module. force_sort_within_sections = true -sections = FUTURE,STDLIB,INBETWEENS,THIRDPARTY,FIRSTPARTY,LOCALFOLDER -default_section = THIRDPARTY known_first_party = homeassistant,tests forced_separate = tests combine_as_imports = true diff --git a/tests/async_mock.py b/tests/async_mock.py index 1942b2ca284b8a..8257ddd3b3bb37 100644 --- a/tests/async_mock.py +++ b/tests/async_mock.py @@ -3,6 +3,7 @@ if sys.version_info[:2] < (3, 8): from asynctest.mock import * # noqa - from asynctest.mock import CoroutineMock as AsyncMock # noqa + + AsyncMock = CoroutineMock # noqa: F405 else: from unittest.mock import * # noqa diff --git a/tests/components/dsmr/test_sensor.py b/tests/components/dsmr/test_sensor.py index ed660eb4f5154f..95608aedba76e0 100644 --- a/tests/components/dsmr/test_sensor.py +++ b/tests/components/dsmr/test_sensor.py @@ -153,8 +153,8 @@ async def test_v4_meter(hass, mock_connection_factory): (connection_factory, transport, protocol) = mock_connection_factory from dsmr_parser.obis_references import ( - HOURLY_GAS_METER_READING, ELECTRICITY_ACTIVE_TARIFF, + HOURLY_GAS_METER_READING, ) from dsmr_parser.objects import CosemObject, MBusObject @@ -198,8 +198,8 @@ async def test_v5_meter(hass, mock_connection_factory): (connection_factory, transport, protocol) = mock_connection_factory from dsmr_parser.obis_references import ( - HOURLY_GAS_METER_READING, ELECTRICITY_ACTIVE_TARIFF, + HOURLY_GAS_METER_READING, ) from dsmr_parser.objects import CosemObject, MBusObject diff --git a/tests/components/mobile_app/test_http_api.py b/tests/components/mobile_app/test_http_api.py index 6cb0858000525a..c5b363c25b05cb 100644 --- a/tests/components/mobile_app/test_http_api.py +++ b/tests/components/mobile_app/test_http_api.py @@ -59,8 +59,8 @@ async def test_registration(hass, hass_client, hass_admin_user): async def test_registration_encryption(hass, hass_client): """Test that registrations happen.""" try: - from nacl.secret import SecretBox from nacl.encoding import Base64Encoder + from nacl.secret import SecretBox except (ImportError, OSError): pytest.skip("libnacl/libsodium is not installed") return diff --git a/tests/components/mobile_app/test_webhook.py b/tests/components/mobile_app/test_webhook.py index bedaa8ce739cd9..dec919317f52af 100644 --- a/tests/components/mobile_app/test_webhook.py +++ b/tests/components/mobile_app/test_webhook.py @@ -22,8 +22,8 @@ def encrypt_payload(secret_key, payload): """Return a encrypted payload given a key and dictionary of data.""" try: - from nacl.secret import SecretBox from nacl.encoding import Base64Encoder + from nacl.secret import SecretBox except (ImportError, OSError): pytest.skip("libnacl/libsodium is not installed") return @@ -45,8 +45,8 @@ def encrypt_payload(secret_key, payload): def decrypt_payload(secret_key, encrypted_data): """Return a decrypted payload given a key and a string of encrypted data.""" try: - from nacl.secret import SecretBox from nacl.encoding import Base64Encoder + from nacl.secret import SecretBox except (ImportError, OSError): pytest.skip("libnacl/libsodium is not installed") return diff --git a/tests/components/owntracks/test_device_tracker.py b/tests/components/owntracks/test_device_tracker.py index 9f47c63aa85a24..9f3694637f3c57 100644 --- a/tests/components/owntracks/test_device_tracker.py +++ b/tests/components/owntracks/test_device_tracker.py @@ -1318,12 +1318,12 @@ def generate_ciphers(secret): # PyNaCl ciphertext generation will fail if the module # cannot be imported. However, the test for decryption # also relies on this library and won't be run without it. - import pickle import base64 + import pickle try: - from nacl.secret import SecretBox from nacl.encoding import Base64Encoder + from nacl.secret import SecretBox keylen = SecretBox.KEY_SIZE key = secret.encode("utf-8") @@ -1369,8 +1369,8 @@ def mock_cipher(): def mock_decrypt(ciphertext, key): """Decrypt/unpickle.""" - import pickle import base64 + import pickle (mkey, plaintext) = pickle.loads(base64.b64decode(ciphertext)) if key != mkey: diff --git a/tests/components/rflink/test_init.py b/tests/components/rflink/test_init.py index fdc60ca726292c..2ae3724ee66704 100644 --- a/tests/components/rflink/test_init.py +++ b/tests/components/rflink/test_init.py @@ -337,6 +337,7 @@ async def test_race_condition(hass, monkeypatch): async def test_not_connected(hass, monkeypatch): """Test Error when sending commands to a disconnected device.""" import pytest + from homeassistant.core import HomeAssistantError test_device = RflinkCommand("DUMMY_DEVICE") diff --git a/tests/components/switcher_kis/test_init.py b/tests/components/switcher_kis/test_init.py index 9e262fafa7eccb..aa187b80d8f42e 100644 --- a/tests/components/switcher_kis/test_init.py +++ b/tests/components/switcher_kis/test_init.py @@ -39,9 +39,10 @@ from tests.common import async_fire_time_changed, async_mock_service if TYPE_CHECKING: - from tests.common import MockUser from aioswitcher.devices import SwitcherV2Device + from tests.common import MockUser + async def test_failed_config( hass: HomeAssistantType, mock_failed_bridge: Generator[None, Any, None] diff --git a/tests/hassfest/test_dependencies.py b/tests/hassfest/test_dependencies.py index b9690107619ead..dcef6d34844f5a 100644 --- a/tests/hassfest/test_dependencies.py +++ b/tests/hassfest/test_dependencies.py @@ -2,6 +2,7 @@ import ast import pytest + from script.hassfest.dependencies import ImportCollector