fix: upgrade to ruff 0.1.0 and fix violations (#422)
This commit is contained in:
parent
fc28bd4079
commit
7e4cab6778
@ -38,7 +38,7 @@ repos:
|
||||
- id: pyupgrade
|
||||
args: [--py39-plus]
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.9.10
|
||||
rev: v0.1.0
|
||||
hooks:
|
||||
- id: ruff
|
||||
args: [--fix, --exit-non-zero-on-fix]
|
||||
|
||||
@ -44,7 +44,7 @@ class BuildExt(build_ext):
|
||||
|
||||
|
||||
def build(setup_kwargs):
|
||||
if os.environ.get("SKIP_CYTHON", False):
|
||||
if os.environ.get("SKIP_CYTHON"):
|
||||
return
|
||||
try:
|
||||
from Cython.Build import cythonize
|
||||
|
||||
@ -7,10 +7,9 @@ sys.path.append(os.path.abspath(os.path.dirname(__file__) + "/.."))
|
||||
import json
|
||||
import signal
|
||||
|
||||
from gi.repository import GLib
|
||||
|
||||
from dbus_fast import Message
|
||||
from dbus_fast.glib import MessageBus
|
||||
from gi.repository import GLib
|
||||
|
||||
main = GLib.MainLoop()
|
||||
bus = MessageBus().connect_sync()
|
||||
|
||||
@ -120,7 +120,6 @@ ignore = [
|
||||
"SIM109", # intended for cython
|
||||
"SIM102", # intended for cython
|
||||
"E501", # too many to fix,
|
||||
"TC001", # too many to fix right now
|
||||
"TID252", # intended
|
||||
"PLC0414", # intended
|
||||
"TRY003", # too many to fix
|
||||
@ -128,7 +127,7 @@ ignore = [
|
||||
"PLR0911", # api is public
|
||||
"PYI036", # too many to fix
|
||||
"PYI034", # too many to fix
|
||||
"TC003", # too many to fix
|
||||
"E721", # many are as intended
|
||||
## should fix these sooner
|
||||
"B007", # too many to fix -- should fix sooner
|
||||
"SIM103", # too many to fix -- should fix sooner
|
||||
@ -138,7 +137,6 @@ ignore = [
|
||||
"B904", # too many to fix -- should fix sooner
|
||||
"PERF401", # too many to fix -- should fix sooner
|
||||
"B904", # too many to fix -- should fix sooner
|
||||
"PLR1704", # too many to fix -- should fix sooner
|
||||
"B006", # too many to fix -- should fix sooner
|
||||
"G004", # too many to fix -- should fix sooner
|
||||
"PT015", # too many to fix -- should fix sooner
|
||||
@ -189,7 +187,6 @@ select = [
|
||||
"SLOT", # flake8-slots
|
||||
"T100", # Trace found: {name} used
|
||||
"T20", # flake8-print
|
||||
"TC", # flake8-type-checking
|
||||
"TID", # Tidy imports
|
||||
"TRY", # tryceratops
|
||||
]
|
||||
@ -227,8 +224,6 @@ select = [
|
||||
"PLR0913", # skip this one
|
||||
"SIM102" , # too many to fix right now
|
||||
"SIM108", # too many to fix right now
|
||||
"TC003", # too many to fix right now
|
||||
"TC002", # too many to fix right now
|
||||
"T201", # too many to fix right now
|
||||
]
|
||||
"bench/**/*" = [
|
||||
@ -238,4 +233,8 @@ select = [
|
||||
"T201", # intended
|
||||
"RSE102", # too many to fix
|
||||
"C408", # too many to fix
|
||||
"E402", # as intended
|
||||
]
|
||||
"docs/**/*" = [
|
||||
"E402", # as intended
|
||||
]
|
||||
|
||||
@ -73,10 +73,10 @@ def get_session_bus_address() -> str:
|
||||
display = os.environ["DISPLAY"]
|
||||
try:
|
||||
display = display_re.search(display).group(1)
|
||||
except Exception:
|
||||
except Exception as ex:
|
||||
raise InvalidAddressError(
|
||||
f"DBUS_SESSION_BUS_ADDRESS not set and could not parse DISPLAY environment variable to get bus address: {display}"
|
||||
)
|
||||
) from ex
|
||||
|
||||
# XXX: this will block but they're very small files and fs operations
|
||||
# should be fairly reliable. fix this by passing in an async func to read
|
||||
@ -90,10 +90,10 @@ def get_session_bus_address() -> str:
|
||||
try:
|
||||
with open(dbus_info_file_name) as f:
|
||||
dbus_info = f.read().rstrip()
|
||||
except Exception:
|
||||
except Exception as ex:
|
||||
raise InvalidAddressError(
|
||||
f"could not open dbus info file: {dbus_info_file_name}"
|
||||
)
|
||||
) from ex
|
||||
|
||||
for line in dbus_info.split("\n"):
|
||||
if line.strip().startswith("DBUS_SESSION_BUS_ADDRESS="):
|
||||
|
||||
@ -186,7 +186,9 @@ class Marshaller:
|
||||
try:
|
||||
return self._construct_buffer()
|
||||
except KeyError as ex:
|
||||
raise NotImplementedError(f'type is not implemented yet: "{ex.args}"')
|
||||
raise NotImplementedError(
|
||||
f'type is not implemented yet: "{ex.args}"'
|
||||
) from ex
|
||||
except error:
|
||||
self.signature_tree.verify(self.body)
|
||||
raise RuntimeError("should not reach here")
|
||||
|
||||
@ -738,9 +738,11 @@ class Unmarshaller:
|
||||
self._serial = _ustr_uint32(self._buf_ustr, 8, endian)
|
||||
self._header_len = _ustr_uint32(self._buf_ustr, 12, endian)
|
||||
elif endian == LITTLE_ENDIAN:
|
||||
self._body_len, self._serial, self._header_len = (
|
||||
UNPACK_HEADER_LITTLE_ENDIAN(self._buf, 4)
|
||||
)
|
||||
(
|
||||
self._body_len,
|
||||
self._serial,
|
||||
self._header_len,
|
||||
) = UNPACK_HEADER_LITTLE_ENDIAN(self._buf, 4)
|
||||
self._uint32_unpack = UINT32_UNPACK_LITTLE_ENDIAN
|
||||
self._int16_unpack = INT16_UNPACK_LITTLE_ENDIAN
|
||||
self._uint16_unpack = UINT16_UNPACK_LITTLE_ENDIAN
|
||||
|
||||
@ -108,9 +108,15 @@ class ErrorType(str, Enum):
|
||||
:seealso: http://man7.org/linux/man-pages/man3/sd-bus-errors.3.html
|
||||
"""
|
||||
|
||||
SERVICE_ERROR = "com.dubstepdish.dbus.next.ServiceError" #: A custom error to indicate an exported service threw an exception.
|
||||
INTERNAL_ERROR = "com.dubstepdish.dbus.next.InternalError" #: A custom error to indicate something went wrong with the library.
|
||||
CLIENT_ERROR = "com.dubstepdish.dbus.next.ClientError" #: A custom error to indicate something went wrong with the client.
|
||||
SERVICE_ERROR = (
|
||||
"com.dubstepdish.dbus.next.ServiceError"
|
||||
) #: A custom error to indicate an exported service threw an exception.
|
||||
INTERNAL_ERROR = (
|
||||
"com.dubstepdish.dbus.next.InternalError"
|
||||
) #: A custom error to indicate something went wrong with the library.
|
||||
CLIENT_ERROR = (
|
||||
"com.dubstepdish.dbus.next.ClientError"
|
||||
) #: A custom error to indicate something went wrong with the client.
|
||||
|
||||
FAILED = "org.freedesktop.DBus.Error.Failed"
|
||||
NO_MEMORY = "org.freedesktop.DBus.Error.NoMemory"
|
||||
|
||||
@ -1033,8 +1033,7 @@ class BaseMessageBus:
|
||||
|
||||
# first build up the result object to know when it's complete
|
||||
result: dict[str, dict[str, Any]] = {
|
||||
node: {interface: None for interface in self._path_exports[node]}
|
||||
for node in nodes
|
||||
node: dict.fromkeys(self._path_exports[node]) for node in nodes
|
||||
}
|
||||
|
||||
if is_result_complete():
|
||||
|
||||
@ -121,7 +121,7 @@ class BaseProxyInterface:
|
||||
return
|
||||
|
||||
match = [s for s in self.introspection.signals if s.name == msg.member]
|
||||
if not len(match):
|
||||
if not match:
|
||||
return
|
||||
intr_signal = match[0]
|
||||
if intr_signal.signature != msg.signature:
|
||||
@ -302,8 +302,10 @@ class BaseProxyObject:
|
||||
intr_interface = next(
|
||||
i for i in self.introspection.interfaces if i.name == name
|
||||
)
|
||||
except StopIteration:
|
||||
raise InterfaceNotFoundError(f"interface not found on this object: {name}")
|
||||
except StopIteration as ex:
|
||||
raise InterfaceNotFoundError(
|
||||
f"interface not found on this object: {name}"
|
||||
) from ex
|
||||
|
||||
interface = self.ProxyInterface(
|
||||
self.bus_name, self.path, intr_interface, self.bus
|
||||
|
||||
@ -33,7 +33,8 @@ HandlerType = Callable[[Message, SendReply], None]
|
||||
|
||||
|
||||
class _MethodCallbackProtocol(Protocol):
|
||||
def __call__(self, interface: ServiceInterface, *args: Any) -> Any: ...
|
||||
def __call__(self, interface: ServiceInterface, *args: Any) -> Any:
|
||||
...
|
||||
|
||||
|
||||
class _Method:
|
||||
@ -206,7 +207,7 @@ def signal(name: str | None = None, disabled: bool = False) -> Callable:
|
||||
|
||||
|
||||
class _Property(property):
|
||||
def set_options(self, options):
|
||||
def set_options(self, options: dict[str, Any]) -> None:
|
||||
self.options = getattr(self, "options", {})
|
||||
for k, v in options.items():
|
||||
self.options[k] = v
|
||||
@ -221,11 +222,7 @@ class _Property(property):
|
||||
else:
|
||||
self.access = PropertyAccess.READWRITE
|
||||
|
||||
if "disabled" in options:
|
||||
self.disabled = options["disabled"]
|
||||
else:
|
||||
self.disabled = False
|
||||
|
||||
self.disabled = options.get("disabled", False)
|
||||
self.introspection = intr.Property(self.name, self.signature, self.access)
|
||||
|
||||
self.__dict__["__DBUS_PROPERTY"] = True
|
||||
|
||||
@ -205,10 +205,10 @@ class SignatureType:
|
||||
def _verify_unix_fd(self, body: Any) -> None:
|
||||
try:
|
||||
self._verify_uint32(body)
|
||||
except SignatureBodyMismatchError:
|
||||
except SignatureBodyMismatchError as ex:
|
||||
raise SignatureBodyMismatchError(
|
||||
'DBus UNIX_FD type "h" must be a valid UINT32'
|
||||
)
|
||||
) from ex
|
||||
|
||||
def _verify_object_path(self, body: Any) -> None:
|
||||
if not is_object_path_valid(body):
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
from pytest_codspeed import BenchmarkFixture
|
||||
|
||||
from dbus_fast import Message
|
||||
from pytest_codspeed import BenchmarkFixture
|
||||
|
||||
message = Message(
|
||||
destination="org.bluez",
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import io
|
||||
|
||||
from pytest_codspeed import BenchmarkFixture
|
||||
|
||||
from dbus_fast._private.unmarshaller import Unmarshaller
|
||||
from pytest_codspeed import BenchmarkFixture
|
||||
|
||||
|
||||
def test_unmarshall_bluez_rssi_message(benchmark: BenchmarkFixture) -> None:
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import pytest
|
||||
|
||||
from dbus_fast import aio
|
||||
from dbus_fast.service import ServiceInterface
|
||||
|
||||
|
||||
@ -3,13 +3,13 @@ import sys
|
||||
from logging.handlers import QueueHandler
|
||||
from queue import SimpleQueue
|
||||
|
||||
import pytest
|
||||
|
||||
import dbus_fast.introspection as intr
|
||||
import pytest
|
||||
from dbus_fast import DBusError, aio, glib
|
||||
from dbus_fast.message import MessageFlag
|
||||
from dbus_fast.service import ServiceInterface, method
|
||||
from dbus_fast.signature import Variant
|
||||
|
||||
from tests.util import check_gi_repository, skip_reason_no_gi
|
||||
|
||||
has_gi = check_gi_repository()
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast import DBusError, Message, aio, glib
|
||||
from dbus_fast.service import PropertyAccess, ServiceInterface, dbus_property
|
||||
from dbus_fast.signature import Variant
|
||||
|
||||
from tests.util import check_gi_repository, skip_reason_no_gi
|
||||
|
||||
has_gi = check_gi_repository()
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast import Message
|
||||
from dbus_fast.aio import MessageBus
|
||||
from dbus_fast.constants import RequestNameReply
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import pytest
|
||||
|
||||
from dbus_fast import Message, MessageType
|
||||
from dbus_fast import introspection as intr
|
||||
from dbus_fast.aio import MessageBus
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import pytest
|
||||
|
||||
from dbus_fast import (
|
||||
DBusError,
|
||||
ErrorType,
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast import (
|
||||
DBusError,
|
||||
ErrorType,
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast import Message, MessageType
|
||||
from dbus_fast.aio import MessageBus
|
||||
from dbus_fast.constants import PropertyAccess
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import pytest
|
||||
|
||||
from dbus_fast import Message, MessageType
|
||||
from dbus_fast import introspection as intr
|
||||
from dbus_fast.aio import MessageBus
|
||||
|
||||
@ -2,7 +2,6 @@ import os
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast._private.address import (
|
||||
get_bus_address,
|
||||
get_session_bus_address,
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import pytest
|
||||
|
||||
from dbus_fast import Message, MessageFlag, MessageType
|
||||
from dbus_fast.aio import MessageBus
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import pytest
|
||||
|
||||
from dbus_fast.aio import MessageBus
|
||||
from dbus_fast.service import ServiceInterface, method
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
"""This tests setting a hardcoded UID in AuthExternal"""
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast.auth import (
|
||||
UID_NOT_SPECIFIED,
|
||||
AuthAnnonymous,
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast import Message, MessageType, aio, glib
|
||||
from dbus_fast.service import ServiceInterface, method
|
||||
|
||||
from tests.util import check_gi_repository, skip_reason_no_gi
|
||||
|
||||
has_gi = check_gi_repository()
|
||||
|
||||
@ -2,7 +2,6 @@ import asyncio
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast import Message
|
||||
from dbus_fast.aio import MessageBus
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast import Message, MessageType
|
||||
from dbus_fast.aio import MessageBus
|
||||
from dbus_fast.service import ServiceInterface, dbus_property, method, signal
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast import Message, MessageFlag, MessageType
|
||||
from dbus_fast.glib import MessageBus
|
||||
|
||||
from tests.util import check_gi_repository, skip_reason_no_gi
|
||||
|
||||
has_gi = check_gi_repository()
|
||||
|
||||
@ -5,7 +5,6 @@ from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast import Message, MessageFlag, MessageType, SignatureTree, Variant
|
||||
from dbus_fast._private._cython_compat import FakeCython
|
||||
from dbus_fast._private.constants import BIG_ENDIAN, LITTLE_ENDIAN
|
||||
@ -234,9 +233,9 @@ def test_unmarshalling_with_table(unmarshall_table):
|
||||
"flags",
|
||||
"serial",
|
||||
]:
|
||||
assert getattr(unmarshaller.message, attr) == getattr(message, attr), (
|
||||
f"attr doesnt match: {attr}"
|
||||
)
|
||||
assert getattr(unmarshaller.message, attr) == getattr(
|
||||
message, attr
|
||||
), f"attr doesnt match: {attr}"
|
||||
|
||||
|
||||
def test_unmarshall_can_resume():
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast import (
|
||||
Message,
|
||||
MessageType,
|
||||
@ -11,6 +10,7 @@ from dbus_fast import (
|
||||
aio,
|
||||
glib,
|
||||
)
|
||||
|
||||
from tests.util import check_gi_repository, skip_reason_no_gi
|
||||
|
||||
has_gi = check_gi_repository()
|
||||
|
||||
@ -2,7 +2,6 @@ import os
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast.constants import ErrorType, MessageType
|
||||
from dbus_fast.errors import DBusError
|
||||
from dbus_fast.message import Message
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import pytest
|
||||
|
||||
from dbus_fast import SignatureBodyMismatchError, SignatureTree, Variant
|
||||
from dbus_fast._private.util import signature_contains_type
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@ import os
|
||||
from contextlib import suppress
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast import Message
|
||||
from dbus_fast._private.address import parse_address
|
||||
from dbus_fast.aio import MessageBus
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
"""Test unpack variants."""
|
||||
|
||||
import pytest
|
||||
|
||||
from dbus_fast.signature import Variant
|
||||
from dbus_fast.unpack import unpack_variants
|
||||
|
||||
|
||||
@ -66,13 +66,13 @@ def test_interface_name_validator():
|
||||
]
|
||||
|
||||
for name in valid_names:
|
||||
assert is_interface_name_valid(name), (
|
||||
f'interface name should be valid: "{name}"'
|
||||
)
|
||||
assert is_interface_name_valid(
|
||||
name
|
||||
), f'interface name should be valid: "{name}"'
|
||||
for name in invalid_names:
|
||||
assert not is_interface_name_valid(name), (
|
||||
f'interface name should be invalid: "{name}"'
|
||||
)
|
||||
assert not is_interface_name_valid(
|
||||
name
|
||||
), f'interface name should be invalid: "{name}"'
|
||||
|
||||
|
||||
def test_member_name_validator():
|
||||
@ -82,6 +82,6 @@ def test_member_name_validator():
|
||||
for member in valid_members:
|
||||
assert is_member_name_valid(member), f'member name should be valid: "{member}"'
|
||||
for member in invalid_members:
|
||||
assert not is_member_name_valid(member), (
|
||||
f'member name should be invalid: "{member}"'
|
||||
)
|
||||
assert not is_member_name_valid(
|
||||
member
|
||||
), f'member name should be invalid: "{member}"'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user