Skip to content

Commit 360b240

Browse files
authored
chore: add pyupgrade to ruff (#118)
* chore: add pyupgrade to ruff * chore: make ruff and isort play nice
1 parent 907ed06 commit 360b240

File tree

12 files changed

+259
-261
lines changed

12 files changed

+259
-261
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ build_command = "pip install poetry && poetry build"
5454
[tool.ruff]
5555
ignore = ["F403", "E741"]
5656
line-length = 120
57+
select=["E", "F", "UP"]
5758

5859
[tool.black]
5960
line-length = 120

roborock/api.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import secrets
1313
import struct
1414
import time
15+
from collections.abc import Callable, Coroutine
1516
from random import randint
16-
from typing import Any, Callable, Coroutine, Optional, Type, TypeVar, final
17+
from typing import Any, TypeVar, final
1718

1819
import aiohttp
1920

@@ -89,7 +90,7 @@ def md5hex(message: str) -> str:
8990

9091

9192
class PreparedRequest:
92-
def __init__(self, base_url: str, base_headers: Optional[dict] = None) -> None:
93+
def __init__(self, base_url: str, base_headers: dict | None = None) -> None:
9394
self.base_url = base_url
9495
self.base_headers = base_headers or {}
9596

@@ -251,7 +252,7 @@ def on_message_received(self, messages: list[RoborockMessage]) -> None:
251252
data_protocol = RoborockDataProtocol(int(data_point_number))
252253
self._logger.debug(f"Got device update for {data_protocol.name}: {data_point}")
253254
if data_protocol in ROBOROCK_DATA_STATUS_PROTOCOL:
254-
_cls: Type[Status] = ModelStatus.get(
255+
_cls: type[Status] = ModelStatus.get(
255256
self.device_info.model, S7MaxVStatus
256257
) # Default to S7 MAXV if we don't have the data
257258
if self.cache[CacheableAttribute.status].value is None:
@@ -301,7 +302,7 @@ def on_message_received(self, messages: list[RoborockMessage]) -> None:
301302
except Exception as ex:
302303
self._logger.exception(ex)
303304

304-
def on_connection_lost(self, exc: Optional[Exception]) -> None:
305+
def on_connection_lost(self, exc: Exception | None) -> None:
305306
self._last_disconnection = self.time_func()
306307
self._logger.info("Roborock client disconnected")
307308
if exc is not None:
@@ -340,7 +341,7 @@ def _async_response(
340341
def _get_payload(
341342
self,
342343
method: RoborockCommand,
343-
params: Optional[list | dict] = None,
344+
params: list | dict | None = None,
344345
secured=False,
345346
):
346347
timestamp = math.floor(time.time())
@@ -372,16 +373,16 @@ async def send_message(self, roborock_message: RoborockMessage):
372373
async def _send_command(
373374
self,
374375
method: RoborockCommand,
375-
params: Optional[list | dict] = None,
376+
params: list | dict | None = None,
376377
):
377378
raise NotImplementedError
378379

379380
@final
380381
async def send_command(
381382
self,
382383
method: RoborockCommand,
383-
params: Optional[list | dict] = None,
384-
return_type: Optional[Type[RT]] = None,
384+
params: list | dict | None = None,
385+
return_type: type[RT] | None = None,
385386
) -> RT:
386387
cacheable_attribute_result = find_cacheable_attribute(method)
387388

@@ -404,7 +405,7 @@ async def send_command(
404405
return response
405406

406407
async def get_status(self) -> Status | None:
407-
_cls: Type[Status] = ModelStatus.get(
408+
_cls: type[Status] = ModelStatus.get(
408409
self.device_info.model, S7MaxVStatus
409410
) # Default to S7 MAXV if we don't have the data
410411
return _cls.from_dict(await self.cache[CacheableAttribute.status].async_value())

roborock/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import logging
55
from pathlib import Path
6-
from typing import Any, Dict
6+
from typing import Any
77

88
import click
99
from pyshark import FileCapture # type: ignore
@@ -29,7 +29,7 @@ def __init__(self):
2929

3030
def reload(self):
3131
if self.roborock_file.is_file():
32-
with open(self.roborock_file, "r") as f:
32+
with open(self.roborock_file) as f:
3333
data = json.load(f)
3434
if data:
3535
self._login_data = LoginData.from_dict(data)
@@ -54,7 +54,7 @@ def login_data(self):
5454
@click.group()
5555
@click.pass_context
5656
def cli(ctx, debug: int):
57-
logging_config: Dict[str, Any] = {"level": logging.DEBUG if debug > 0 else logging.INFO}
57+
logging_config: dict[str, Any] = {"level": logging.DEBUG if debug > 0 else logging.INFO}
5858
logging.basicConfig(**logging_config) # type: ignore
5959
ctx.obj = RoborockContext()
6060

@@ -153,7 +153,7 @@ async def parser(_, local_key, device_ip, file):
153153
else:
154154
_LOGGER.info("Listen for interface rvi0 since no file was provided")
155155
capture = LiveCapture(interface="rvi0")
156-
buffer = {"data": bytes()}
156+
buffer = {"data": b""}
157157

158158
def on_package(packet: Packet):
159159
if hasattr(packet, "ip"):

roborock/cloud_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import threading
77
import uuid
88
from asyncio import Lock, Task
9-
from typing import Any, Optional
9+
from typing import Any
1010
from urllib.parse import urlparse
1111

1212
import paho.mqtt.client as mqtt
@@ -199,7 +199,7 @@ async def send_message(self, roborock_message: RoborockMessage):
199199
async def _send_command(
200200
self,
201201
method: RoborockCommand,
202-
params: Optional[list | dict] = None,
202+
params: list | dict | None = None,
203203
):
204204
request_id, timestamp, payload = super()._get_payload(method, params, True)
205205
request_protocol = RoborockMessageProtocol.RPC_REQUEST

roborock/code_mappings.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import logging
44
from enum import IntEnum
5-
from typing import Type
65

76
_LOGGER = logging.getLogger(__name__)
87

@@ -15,7 +14,7 @@ def name(self) -> str:
1514
return super().name.lower()
1615

1716
@classmethod
18-
def _missing_(cls: Type[RoborockEnum], key) -> RoborockEnum:
17+
def _missing_(cls: type[RoborockEnum], key) -> RoborockEnum:
1918
if hasattr(cls, "unknown"):
2019
_LOGGER.warning(f"Missing {cls.__name__} code: {key} - defaulting to 'unknown'")
2120
return cls.unknown # type: ignore
@@ -24,23 +23,23 @@ def _missing_(cls: Type[RoborockEnum], key) -> RoborockEnum:
2423
return default_value
2524

2625
@classmethod
27-
def as_dict(cls: Type[RoborockEnum]):
26+
def as_dict(cls: type[RoborockEnum]):
2827
return {i.name: i.value for i in cls if i.name != "missing"}
2928

3029
@classmethod
31-
def as_enum_dict(cls: Type[RoborockEnum]):
30+
def as_enum_dict(cls: type[RoborockEnum]):
3231
return {i.value: i for i in cls if i.name != "missing"}
3332

3433
@classmethod
35-
def values(cls: Type[RoborockEnum]) -> list[int]:
34+
def values(cls: type[RoborockEnum]) -> list[int]:
3635
return list(cls.as_dict().values())
3736

3837
@classmethod
39-
def keys(cls: Type[RoborockEnum]) -> list[str]:
38+
def keys(cls: type[RoborockEnum]) -> list[str]:
4039
return list(cls.as_dict().keys())
4140

4241
@classmethod
43-
def items(cls: Type[RoborockEnum]):
42+
def items(cls: type[RoborockEnum]):
4443
return cls.as_dict().items()
4544

4645

roborock/command_cache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

3+
from collections.abc import Mapping
34
from dataclasses import dataclass, field
45
from enum import Enum
5-
from typing import Mapping, Optional
66

77
from roborock import RoborockCommand
88

@@ -38,9 +38,9 @@ class CacheableAttribute(str, Enum):
3838
class RoborockAttribute:
3939
attribute: str
4040
get_command: RoborockCommand
41-
add_command: Optional[RoborockCommand] = None
42-
set_command: Optional[RoborockCommand] = None
43-
close_command: Optional[RoborockCommand] = None
41+
add_command: RoborockCommand | None = None
42+
set_command: RoborockCommand | None = None
43+
close_command: RoborockCommand | None = None
4444
additional_change_commands: list[RoborockCommand] = field(default_factory=list)
4545

4646

0 commit comments

Comments
 (0)