Ruff: Add and fix UP rules

This commit is contained in:
Josh Wu
2026-01-01 03:07:06 +08:00
parent 8e28f4e159
commit 3f643de4c1
102 changed files with 922 additions and 999 deletions

View File

@@ -19,7 +19,7 @@ import asyncio
import logging
import os
import struct
from typing import Awaitable
from collections.abc import Awaitable
import pytest

View File

@@ -18,7 +18,6 @@
import asyncio
import logging
import os
from typing import Optional
import pytest
import pytest_asyncio
@@ -113,8 +112,8 @@ def _default_ag_sdp_features() -> hfp.AgSdpFeature:
# -----------------------------------------------------------------------------
async def make_hfp_connections(
hf_config: Optional[hfp.HfConfiguration] = None,
ag_config: Optional[hfp.AgConfiguration] = None,
hf_config: hfp.HfConfiguration | None = None,
ag_config: hfp.AgConfiguration | None = None,
):
if not hf_config:
hf_config = _default_hf_configuration()

View File

@@ -118,7 +118,7 @@ async def test_basic(temporary_file):
assert foo.ltk is not None
assert foo.ltk.value == ltk
with open(file.name, "r", encoding="utf-8") as json_file:
with open(file.name, encoding="utf-8") as json_file:
json_data = json.load(json_file)
assert 'my_namespace' in json_data
assert 'foo' in json_data['my_namespace']
@@ -161,7 +161,7 @@ async def test_default_namespace(temporary_file):
ltk = bytes([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
keys.ltk = PairingKeys.Key(ltk)
await keystore.update('foo', keys)
with open(file.name, "r", encoding="utf-8") as json_file:
with open(file.name, encoding="utf-8") as json_file:
json_data = json.load(json_file)
assert '__DEFAULT__' in json_data
assert 'foo' in json_data['__DEFAULT__']

View File

@@ -20,7 +20,6 @@ import itertools
import logging
import os
import random
import struct
from collections.abc import Sequence
from unittest import mock

View File

@@ -87,7 +87,7 @@ async def test_update_track_title(gmcs_context):
await gmcs_context.devices[0].notify_subscribers(
gmcs_context.server.track_title_characteristic,
value="My Song".encode(),
value=b"My Song",
)
assert (await asyncio.wait_for(state.get(), TIMEOUT)) == "My Song"

View File

@@ -16,7 +16,7 @@
# Imports
# -----------------------------------------------------------------------------
from typing import Any, Optional
from typing import Any
from unittest import mock
import pytest
@@ -294,7 +294,7 @@ def test_link_key_to_ltk(ct2: bool, expected: str, crypto_backend: Any):
)
@pytest.mark.asyncio
async def test_send_identity_address_command(
identity_address_type: Optional[pairing.PairingConfig.AddressType],
identity_address_type: pairing.PairingConfig.AddressType | None,
public_address: Address,
random_address: Address,
expected_identity_address: Address,

View File

@@ -17,7 +17,6 @@
# -----------------------------------------------------------------------------
import asyncio
import functools
from typing import Optional
from typing_extensions import Self
@@ -32,7 +31,7 @@ from bumble.transport.common import AsyncPipeSink
# -----------------------------------------------------------------------------
class Devices:
connections: list[Optional[Connection]]
connections: list[Connection | None]
def __init__(self, num_devices: int) -> None:
self.connections = [None for _ in range(num_devices)]