From d7dda6bee51fd7603594dd33a218a0b3862b5242 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 23 Jan 2023 07:56:15 +0100 Subject: [PATCH] Update python version used for pylint [Py310] (#86414) * Update python version used for pylint linting [Py310] * Import Callable from collections.abc [Py310] * Use builtin anext [Py310] --- homeassistant/components/harmony/subscriber.py | 6 ++---- homeassistant/components/knx/config_flow.py | 2 +- homeassistant/components/mqtt/client.py | 7 ++----- pyproject.toml | 6 +++++- tests/components/anthemav/conftest.py | 2 +- tests/components/anthemav/test_init.py | 2 +- tests/components/anthemav/test_media_player.py | 2 +- tests/components/logbook/test_init.py | 2 +- tests/components/pushover/test_init.py | 3 +-- tests/components/unifiprotect/utils.py | 4 ++-- tests/components/wiz/__init__.py | 2 +- 11 files changed, 18 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/harmony/subscriber.py b/homeassistant/components/harmony/subscriber.py index 092eb0d6859..0c22d4b38b9 100644 --- a/homeassistant/components/harmony/subscriber.py +++ b/homeassistant/components/harmony/subscriber.py @@ -2,11 +2,9 @@ from __future__ import annotations import asyncio +from collections.abc import Callable import logging - -# Issue with Python 3.9.0 and 3.9.1 with collections.abc.Callable -# https://bugs.python.org/issue42965 -from typing import Any, Callable, NamedTuple, Optional +from typing import Any, NamedTuple, Optional from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback diff --git a/homeassistant/components/knx/config_flow.py b/homeassistant/components/knx/config_flow.py index b03a59b2d4e..7465c394dd1 100644 --- a/homeassistant/components/knx/config_flow.py +++ b/homeassistant/components/knx/config_flow.py @@ -153,7 +153,7 @@ class KNXCommonFlow(ABC, FlowHandler): # keep a reference to the generator to scan in background until user selects a connection type self._async_scan_gen = self._gatewayscanner.async_scan() try: - await self._async_scan_gen.__anext__() + await anext(self._async_scan_gen) except StopAsyncIteration: pass # scan finished, no interfaces discovered else: diff --git a/homeassistant/components/mqtt/client.py b/homeassistant/components/mqtt/client.py index aa30c6c18af..75e8c2e46ec 100644 --- a/homeassistant/components/mqtt/client.py +++ b/homeassistant/components/mqtt/client.py @@ -1,11 +1,8 @@ """Support for MQTT message handling.""" -# pylint: disable=deprecated-typing-alias -# In Python 3.9.0 and 3.9.1 collections.abc.Callable -# can't be used inside typing.Union or typing.Optional from __future__ import annotations import asyncio -from collections.abc import Coroutine, Iterable +from collections.abc import Callable, Coroutine, Iterable from functools import lru_cache, partial, wraps import inspect from itertools import groupby @@ -13,7 +10,7 @@ import logging from operator import attrgetter import ssl import time -from typing import TYPE_CHECKING, Any, Callable, Union, cast +from typing import TYPE_CHECKING, Any, Union, cast import uuid import attr diff --git a/pyproject.toml b/pyproject.toml index a927ab18863..e2ec3ddc12f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,7 +92,7 @@ forced_separate = [ combine_as_imports = true [tool.pylint.MAIN] -py-version = "3.9" +py-version = "3.10" ignore = [ "tests", ] @@ -164,6 +164,9 @@ good-names = [ # Enable once current issues are fixed: # consider-using-namedtuple-or-dataclass (Pylint CodeStyle extension) # consider-using-assignment-expr (Pylint CodeStyle extension) +# --- +# Temporary for the Python 3.10 update +# consider-alternative-union-syntax disable = [ "format", "abstract-method", @@ -188,6 +191,7 @@ disable = [ "consider-using-f-string", "consider-using-namedtuple-or-dataclass", "consider-using-assignment-expr", + "consider-alternative-union-syntax", ] enable = [ #"useless-suppression", # temporarily every now and then to clean them up diff --git a/tests/components/anthemav/conftest.py b/tests/components/anthemav/conftest.py index 595c867304b..89dba9563d1 100644 --- a/tests/components/anthemav/conftest.py +++ b/tests/components/anthemav/conftest.py @@ -1,5 +1,5 @@ """Fixtures for anthemav integration tests.""" -from typing import Callable +from collections.abc import Callable from unittest.mock import AsyncMock, MagicMock, patch import pytest diff --git a/tests/components/anthemav/test_init.py b/tests/components/anthemav/test_init.py index 63bd8390958..019668769ed 100644 --- a/tests/components/anthemav/test_init.py +++ b/tests/components/anthemav/test_init.py @@ -1,5 +1,5 @@ """Test the Anthem A/V Receivers config flow.""" -from typing import Callable +from collections.abc import Callable from unittest.mock import ANY, AsyncMock, patch from anthemav.device_error import DeviceError diff --git a/tests/components/anthemav/test_media_player.py b/tests/components/anthemav/test_media_player.py index e6a4e60108a..2609ee46dd8 100644 --- a/tests/components/anthemav/test_media_player.py +++ b/tests/components/anthemav/test_media_player.py @@ -1,5 +1,5 @@ """Test the Anthem A/V Receivers config flow.""" -from typing import Callable +from collections.abc import Callable from unittest.mock import AsyncMock import pytest diff --git a/tests/components/logbook/test_init.py b/tests/components/logbook/test_init.py index e831987f1a9..2bc08cab866 100644 --- a/tests/components/logbook/test_init.py +++ b/tests/components/logbook/test_init.py @@ -2,10 +2,10 @@ # pylint: disable=invalid-name import asyncio import collections +from collections.abc import Callable from datetime import datetime, timedelta from http import HTTPStatus import json -from typing import Callable from unittest.mock import Mock, patch import pytest diff --git a/tests/components/pushover/test_init.py b/tests/components/pushover/test_init.py index 635aec520b5..ae49881a741 100644 --- a/tests/components/pushover/test_init.py +++ b/tests/components/pushover/test_init.py @@ -1,6 +1,5 @@ """Test pushbullet integration.""" -from collections.abc import Awaitable -from typing import Callable +from collections.abc import Awaitable, Callable from unittest.mock import MagicMock, patch import aiohttp diff --git a/tests/components/unifiprotect/utils.py b/tests/components/unifiprotect/utils.py index fc4c2ed1104..2d6ab9937a3 100644 --- a/tests/components/unifiprotect/utils.py +++ b/tests/components/unifiprotect/utils.py @@ -2,10 +2,10 @@ from __future__ import annotations -from collections.abc import Sequence +from collections.abc import Callable, Sequence from dataclasses import dataclass from datetime import timedelta -from typing import Any, Callable +from typing import Any from unittest.mock import Mock from pyunifiprotect import ProtectApiClient diff --git a/tests/components/wiz/__init__.py b/tests/components/wiz/__init__.py index 93033d984fa..0f88a1db7b5 100644 --- a/tests/components/wiz/__init__.py +++ b/tests/components/wiz/__init__.py @@ -1,9 +1,9 @@ """Tests for the WiZ Platform integration.""" +from collections.abc import Callable from contextlib import contextmanager from copy import deepcopy import json -from typing import Callable from unittest.mock import AsyncMock, MagicMock, patch from pywizlight import SCENES, BulbType, PilotParser, wizlight