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

Use Ruff pyupgrade and pycodestyle #511

Merged
merged 2 commits into from
Oct 24, 2023
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
7 changes: 4 additions & 3 deletions pydeconz/gateway.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Python library to connect deCONZ and Home Assistant to work together."""

from asyncio import CancelledError, Task, create_task, sleep
from collections.abc import Callable
import logging
from pprint import pformat
from typing import Any, Callable
from typing import Any

import aiohttp

Expand Down Expand Up @@ -182,7 +183,7 @@ async def _request(
async with self.session.request(method, url, json=json) as res:
if res.content_type != "application/json":
raise ResponseError(
"Invalid content type: {} ({})".format(res.content_type, res)
f"Invalid content type: {res.content_type} ({res})"
)

response = await res.json()
Expand All @@ -194,7 +195,7 @@ async def _request(

except aiohttp.client_exceptions.ClientError as err:
raise RequestError(
"Error requesting data from {}: {}".format(self.host, err)
f"Error requesting data from {self.host}: {err}"
) from None

async def session_handler(self, signal: Signal) -> None:
Expand Down
11 changes: 9 additions & 2 deletions pydeconz/interfaces/api_handlers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
"""API handler base classes."""

from collections.abc import Callable, ItemsView, ValuesView
from collections.abc import (
Callable,
ItemsView,
Iterable,
Iterator,
KeysView,
ValuesView,
)
import itertools
from typing import TYPE_CHECKING, Any, Generic, Iterable, Iterator, KeysView
from typing import TYPE_CHECKING, Any, Generic

from ..models import DataResource, ResourceGroup, ResourceType
from ..models.event import Event, EventType
Expand Down
3 changes: 2 additions & 1 deletion pydeconz/interfaces/events.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Mange events from deCONZ."""

from collections.abc import Callable
import logging
from typing import TYPE_CHECKING, Any, Callable
from typing import TYPE_CHECKING, Any

from ..models import ResourceGroup
from ..models.event import Event, EventType
Expand Down
9 changes: 4 additions & 5 deletions pydeconz/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Python library to connect deCONZ and Home Assistant to work together."""

from collections.abc import Callable
import logging
from typing import Any, Callable, Final, TypedDict
from typing import Any, Final, TypedDict

import aiohttp

Expand Down Expand Up @@ -95,7 +96,7 @@ async def request(
res = await session(url, **kwargs)

if res.content_type != "application/json":
raise ResponseError("Invalid content type: {}".format(res.content_type))
raise ResponseError(f"Invalid content type: {res.content_type}")

response = await res.json()
LOGGER.debug("HTTP request response: %s", response)
Expand All @@ -105,9 +106,7 @@ async def request(
return response

except aiohttp.client_exceptions.ClientError as err:
raise RequestError(
"Error requesting data from {}: {}".format(url, err)
) from None
raise RequestError(f"Error requesting data from {url}: {err}") from None


def _raise_on_error(data: list[dict[str, Any]] | dict[str, Any]) -> None:
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ target-version = "py310"
select = [
"I", # isort
"RUF006", # Store a reference to the return value of asyncio.create_task
"UP", # pyupgrade
"W", # pycodestyle
]

[tool.ruff.isort]
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Setup common test helpers."""

from typing import Iterator
from collections.abc import Iterator
from unittest.mock import Mock, patch

import aiohttp
Expand All @@ -27,7 +27,6 @@ def deconz_called_with(mock_aioresponse):
def verify_call(method: str, path: str, **kwargs: dict) -> bool:
"""Verify expected data was provided with a request to aioresponse."""
for req, call_list in mock_aioresponse.requests.items():

if method != req[0]:
continue

Expand Down
Loading