Ruff updates (#915)

This commit is contained in:
Jesse Hills 2024-08-05 13:42:21 +12:00 committed by GitHub
parent 098d6d263e
commit a0b87778b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 96 additions and 85 deletions

View File

@ -67,7 +67,6 @@ jobs:
run: | run: |
echo "::add-matcher::.github/workflows/matchers/flake8.json" echo "::add-matcher::.github/workflows/matchers/flake8.json"
echo "::add-matcher::.github/workflows/matchers/pylint.json" echo "::add-matcher::.github/workflows/matchers/pylint.json"
echo "::add-matcher::.github/workflows/matchers/isort.json"
echo "::add-matcher::.github/workflows/matchers/mypy.json" echo "::add-matcher::.github/workflows/matchers/mypy.json"
echo "::add-matcher::.github/workflows/matchers/pytest.json" echo "::add-matcher::.github/workflows/matchers/pytest.json"
@ -80,9 +79,6 @@ jobs:
- run: black --check --diff --color aioesphomeapi tests - run: black --check --diff --color aioesphomeapi tests
name: Check formatting with black name: Check formatting with black
if: ${{ matrix.python-version == '3.11' && matrix.extension == 'skip_cython' }} if: ${{ matrix.python-version == '3.11' && matrix.extension == 'skip_cython' }}
- run: isort --check --diff aioesphomeapi tests
name: Check import order with isort
if: ${{ matrix.python-version == '3.11' && matrix.extension == 'skip_cython' }}
- run: mypy aioesphomeapi - run: mypy aioesphomeapi
name: Check typing with mypy name: Check typing with mypy
if: ${{ matrix.python-version == '3.11' && matrix.extension == 'skip_cython' }} if: ${{ matrix.python-version == '3.11' && matrix.extension == 'skip_cython' }}

View File

@ -1,35 +1,32 @@
--- ---
exclude: '^aioesphomeapi/api.*$' exclude: '^aioesphomeapi/api.*$'
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0 rev: v3.2.0
hooks: hooks:
- id: trailing-whitespace - id: trailing-whitespace
- id: end-of-file-fixer - id: end-of-file-fixer
- id: check-added-large-files - id: check-added-large-files
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
rev: v2.37.1 rev: v2.37.1
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: [--py37-plus] args: [--py39-plus]
- repo: https://github.com/PyCQA/isort - repo: https://github.com/astral-sh/ruff-pre-commit
rev: 5.12.0 rev: v0.5.4
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.1
hooks: hooks:
- id: ruff - id: ruff
args: args: [--fix]
- --fix - id: ruff-format
- repo: https://github.com/psf/black-pre-commit-mirror - repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.1.1 rev: 24.1.1
hooks: hooks:
- id: black - id: black
args: args:
- --safe
- --quiet - --quiet
files: ^((aioesphomeapi|tests)/.+)?[^/]+\.py$ files: ^((aioesphomeapi|tests)/.+)?[^/]+\.py$
- repo: https://github.com/cdce8p/python-typing-update - repo: https://github.com/cdce8p/python-typing-update
rev: v0.6.0 rev: v0.6.0
hooks: hooks:
- id: python-typing-update - id: python-typing-update

View File

@ -1,8 +1,8 @@
from __future__ import annotations from __future__ import annotations
from abc import abstractmethod
import asyncio import asyncio
import logging import logging
from abc import abstractmethod
from typing import TYPE_CHECKING, Callable, cast from typing import TYPE_CHECKING, Callable, cast
from ..core import SocketClosedAPIError from ..core import SocketClosedAPIError

View File

@ -2,8 +2,8 @@ from __future__ import annotations
import asyncio import asyncio
import binascii import binascii
import logging
from functools import partial from functools import partial
import logging
from struct import Struct from struct import Struct
from typing import TYPE_CHECKING, Any, Callable from typing import TYPE_CHECKING, Any, Callable

View File

@ -2,9 +2,9 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
import logging
from collections.abc import Awaitable, Coroutine from collections.abc import Awaitable, Coroutine
from functools import partial from functools import partial
import logging
from typing import TYPE_CHECKING, Any, Callable, Union from typing import TYPE_CHECKING, Any, Callable, Union
from google.protobuf import message from google.protobuf import message
@ -127,9 +127,7 @@ from .model import (
UserService, UserService,
UserServiceArgType, UserServiceArgType,
VoiceAssistantAudioData, VoiceAssistantAudioData,
) VoiceAssistantAudioSettings as VoiceAssistantAudioSettingsModel,
from .model import VoiceAssistantAudioSettings as VoiceAssistantAudioSettingsModel
from .model import (
VoiceAssistantCommand, VoiceAssistantCommand,
VoiceAssistantEventType, VoiceAssistantEventType,
VoiceAssistantSubscriptionFlag, VoiceAssistantSubscriptionFlag,
@ -951,8 +949,7 @@ class APIClient:
req.tilt = tilt req.tilt = tilt
if stop: if stop:
req.stop = stop req.stop = stop
else: elif stop:
if stop:
req.legacy_command = LegacyCoverCommand.STOP req.legacy_command = LegacyCoverCommand.STOP
req.has_legacy_command = True req.has_legacy_command = True
elif position == 1.0: elif position == 1.0:

View File

@ -1,18 +1,17 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
# After we drop support for Python 3.10, we can use the built-in TimeoutError
# instead of the one from asyncio since they are the same in Python 3.11+
from asyncio import CancelledError, TimeoutError as asyncio_TimeoutError
from dataclasses import astuple, dataclass
import enum import enum
from functools import lru_cache, partial
import logging import logging
import socket import socket
import sys import sys
import time import time
# After we drop support for Python 3.10, we can use the built-in TimeoutError
# instead of the one from asyncio since they are the same in Python 3.11+
from asyncio import CancelledError
from asyncio import TimeoutError as asyncio_TimeoutError
from dataclasses import astuple, dataclass
from functools import lru_cache, partial
from typing import TYPE_CHECKING, Any, Callable from typing import TYPE_CHECKING, Any, Callable
import aiohappyeyeballs import aiohappyeyeballs
@ -226,9 +225,7 @@ class APIConnection:
self._params = params self._params = params
self.on_stop: Callable[[bool], None] | None = on_stop self.on_stop: Callable[[bool], None] | None = on_stop
self._socket: socket.socket | None = None self._socket: socket.socket | None = None
self._frame_helper: None | (APINoiseFrameHelper | APIPlaintextFrameHelper) = ( self._frame_helper: None | APINoiseFrameHelper | APIPlaintextFrameHelper = None
None
)
self.api_version: APIVersion | None = None self.api_version: APIVersion | None = None
self.connection_state = CONNECTION_STATE_INITIALIZED self.connection_state = CONNECTION_STATE_INITIALIZED

View File

@ -1,10 +1,10 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
import logging
import socket
from dataclasses import dataclass from dataclasses import dataclass
from ipaddress import IPv4Address, IPv6Address, ip_address from ipaddress import IPv4Address, IPv6Address, ip_address
import logging
import socket
from typing import TYPE_CHECKING, cast from typing import TYPE_CHECKING, cast
from zeroconf import IPVersion from zeroconf import IPVersion

View File

@ -3,9 +3,9 @@ from __future__ import annotations
# Helper script and aioesphomeapi to view logs from an esphome device # Helper script and aioesphomeapi to view logs from an esphome device
import argparse import argparse
import asyncio import asyncio
from datetime import datetime
import logging import logging
import sys import sys
from datetime import datetime
from .api_pb2 import SubscribeLogsResponse # type: ignore from .api_pb2 import SubscribeLogsResponse # type: ignore
from .client import APIClient from .client import APIClient

View File

@ -1,7 +1,7 @@
from __future__ import annotations from __future__ import annotations
import logging
from collections.abc import Coroutine from collections.abc import Coroutine
import logging
from typing import Any, Callable from typing import Any, Callable
from zeroconf.asyncio import AsyncZeroconf from zeroconf.asyncio import AsyncZeroconf

View File

@ -1,10 +1,10 @@
from __future__ import annotations from __future__ import annotations
import enum
import sys
from collections.abc import Iterable from collections.abc import Iterable
from dataclasses import asdict, dataclass, field, fields from dataclasses import asdict, dataclass, field, fields
import enum
from functools import cache, lru_cache, partial from functools import cache, lru_cache, partial
import sys
from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast
from uuid import UUID from uuid import UUID

View File

@ -1,15 +1,14 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
import logging
import time
from collections.abc import Awaitable from collections.abc import Awaitable
from enum import Enum from enum import Enum
import logging
import time
from typing import Callable from typing import Callable
import zeroconf import zeroconf
from zeroconf.const import _TYPE_A as TYPE_A from zeroconf.const import _TYPE_A as TYPE_A, _TYPE_PTR as TYPE_PTR
from zeroconf.const import _TYPE_PTR as TYPE_PTR
from .client import APIClient from .client import APIClient
from .core import ( from .core import (

View File

@ -1,8 +1,3 @@
[tool.isort]
profile = "black"
multi_line_output = 3
extend_skip = ["api_pb2.py", "api_options_pb2.py"]
[tool.black] [tool.black]
exclude = 'api_pb2.py|api_options_pb2.py' exclude = 'api_pb2.py|api_options_pb2.py'
target-version = ['py39'] target-version = ['py39']
@ -31,9 +26,39 @@ disable = [
] ]
[tool.ruff] [tool.ruff]
ignore = [ required-version = ">=0.5.0"
"E721", # We want type() check for protobuf messages exclude = [
"aioesphomeapi/api_pb2.py",
"aioesphomeapi/api_options_pb2.py",
] ]
[tool.ruff.lint]
select = [
"E", # pycodestyle
"F", # pyflakes/autoflake
"I", # isort
"PL", # pylint
"UP", # pyupgrade
]
ignore = [
"E501", # line too long
"E721", # We want type() check for protobuf messages
"PLR0911", # Too many return statements ({returns} > {max_returns})
"PLR0912", # Too many branches ({branches} > {max_branches})
"PLR0913", # Too many arguments to function call ({c_args} > {max_args})
"PLR0915", # Too many statements ({statements} > {max_statements})
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
"PLW2901", # Outer {outer_kind} variable {name} overwritten by inner {inner_kind} target
]
[tool.ruff.lint.isort]
force-sort-within-sections = true
known-first-party = [
"aioesphomeapi",
]
combine-as-imports = true
split-on-trailing-comma = false
[build-system] [build-system]
requires = ['setuptools>=65.4.1', 'wheel', 'Cython>=3.0.2'] requires = ['setuptools>=65.4.1', 'wheel', 'Cython>=3.0.2']