chore: enable some more ruff rules (#414)

This commit is contained in:
J. Nick Koston 2025-03-06 12:49:12 -10:00 committed by GitHub
parent a589651511
commit 2bad648c61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 268 additions and 163 deletions

View File

@ -1,8 +1,11 @@
"""Build optional cython modules."""
import logging
import os
from distutils.command.build_ext import build_ext
_LOGGER = logging.getLogger(__name__)
try:
from setuptools import Extension
except ImportError:
@ -37,7 +40,7 @@ class BuildExt(build_ext):
try:
super().build_extensions()
except Exception:
pass
_LOGGER.debug("Failed to build extensions", exc_info=True)
def build(setup_kwargs):
@ -47,13 +50,13 @@ def build(setup_kwargs):
from Cython.Build import cythonize
setup_kwargs.update(
dict(
ext_modules=cythonize(
{
"ext_modules": cythonize(
EXTENSIONS,
compiler_directives={"language_level": "3"}, # Python 3
),
cmdclass=dict(build_ext=BuildExt),
)
"cmdclass": {"build_ext": BuildExt},
}
)
setup_kwargs["exclude_package_data"] = {
pkg: ["*.c"] for pkg in setup_kwargs["packages"]
@ -61,4 +64,3 @@ def build(setup_kwargs):
except Exception:
if os.environ.get("REQUIRE_CYTHON"):
raise
pass

View File

@ -125,8 +125,7 @@ async def main():
def default(o):
if type(o) is Variant:
return [o.signature, o.value]
else:
raise json.JSONDecodeError()
raise json.JSONDecodeError()
print(json.dumps(result.body, indent=2, default=default))

View File

@ -114,7 +114,127 @@ line-length = 88
[tool.ruff.lint]
ignore = [
"F821", # undefined names are used for decorators
"S101", # use of assert detected
"S105", # too many false positives
"SLF001", # intended
"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
"PLR2004", # way too many to fix right now
"PLR0911", # api is public
"PYI036", # too many to fix
"PYI034", # too many to fix
"TC003", # too many to fix
## should fix these sooner
"B007", # too many to fix -- should fix sooner
"SIM103", # too many to fix -- should fix sooner
"SIM110", # too many to fix -- should fix sooner
"RUF012", # too many to fix -- should fix sooner
"TRY002", # too many to fix -- should fix sooner
"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
"B011", # too many to fix -- should fix sooner
"PLR1714", # too many to fix -- should fix sooner
"PLR0915", # too many to fix -- should fix sooner
"PERF102", # too many to fix -- should fix sooner
"TRY401", # too many to fix -- should fix sooner
"PLR0913", # too many to fix -- should fix sooner
"PLR0912", # too many to fix -- should fix sooner
"PERF203", # too many to fix -- should fix sooner
"G201", # too many to fix -- should fix sooner
"TRY301", # too many to fix -- should fix sooner
"B020", # too many to fix -- should fix sooner
"S314", # too many to fix -- should fix sooner
"RET504", # too many to fix -- should fix sooner
"SIM105", # too many to fix -- should fix sooner
"TRY300", # too many to fix -- should fix sooner
"PLW2901", # too many to fix -- should fix sooner
"PERF402", # too many to fix -- should fix sooner
]
select = [
"I", # isort formatting.
"ASYNC", # async rules
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"S", # flake8-bandit
"F", # pyflake
"E", # pycodestyle
"W", # pycodestyle
"UP", # pyupgrade
"I", # isort
"RUF", # ruff specific
"FLY", # flynt
"FURB", # refurb
"G", # flake8-logging-format ,
"PERF", # Perflint
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PYI", # flake8-pyi
"RET", # flake8-return
"RSE", # flake8-raise ,
"SIM", # flake8-simplify
"SLF", # flake8-self
"SLOT", # flake8-slots
"T100", # Trace found: {name} used
"T20", # flake8-print
"TC", # flake8-type-checking
"TID", # Tidy imports
"TRY", # tryceratops
]
[tool.ruff.lint.per-file-ignores]
"tests/**/*" = [
"D100",
"D101",
"D102",
"D103",
"D104",
"S101",
"S108",
"SLF001",
"PLW", # too many to fix
"TRY",# too many to fix right now
"PT",# too many to fix right now
"B",# too many to fix right now
"RET",# too many to fix right now
"PLR2004", # too many to fix right now
"PT011", # too many to fix right now
"PT006", # too many to fix right now
"PGH003", # too many to fix right now
"PT007", # too many to fix right now
"PT027", # too many to fix right now
"PLW0603" , # too many to fix right now
"PLR0915", # too many to fix right now
"FLY002", # too many to fix right now
"PT018", # too many to fix right now
"PLR0124", # too many to fix right now
"SIM202" , # too many to fix right now
"PT012" , # too many to fix right now
"TID252", # too many to fix right now
"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/**/*" = [
"T201", # intended
]
"examples/**/*" = [
"T201", # intended
"RSE102", # too many to fix
"C408", # too many to fix
]

View File

@ -40,21 +40,11 @@ from .validators import (
)
__all__ = [
"introspection",
"message_bus",
"proxy_object",
"service",
"ArgDirection",
"BusType",
"ErrorType",
"MessageFlag",
"MessageType",
"NameFlag",
"PropertyAccess",
"ReleaseNameReply",
"RequestNameReply",
"AuthError",
"BusType",
"DBusError",
"ErrorType",
"InterfaceNotFoundError",
"InvalidAddressError",
"InvalidBusNameError",
@ -64,9 +54,15 @@ __all__ = [
"InvalidMessageError",
"InvalidObjectPathError",
"InvalidSignatureError",
"Message",
"MessageFlag",
"MessageType",
"NameFlag",
"PropertyAccess",
"ReleaseNameReply",
"RequestNameReply",
"SignalDisabledError",
"SignatureBodyMismatchError",
"Message",
"SignatureTree",
"SignatureType",
"Variant",
@ -74,9 +70,13 @@ __all__ = [
"assert_interface_name_valid",
"assert_member_name_valid",
"assert_object_path_valid",
"introspection",
"is_bus_name_valid",
"is_interface_name_valid",
"is_member_name_valid",
"is_object_path_valid",
"message_bus",
"proxy_object",
"service",
"unpack_variants",
]

View File

@ -9,8 +9,8 @@ PACK_LITTLE_ENDIAN = "<"
PACK_UINT32 = Struct(f"{PACK_LITTLE_ENDIAN}I").pack
PACKED_UINT32_ZERO = PACK_UINT32(0)
PACKED_BOOL_FALSE = PACK_UINT32(int(0))
PACKED_BOOL_TRUE = PACK_UINT32(int(1))
PACKED_BOOL_FALSE = PACK_UINT32(0)
PACKED_BOOL_TRUE = PACK_UINT32(1)
_int = int
_bytes = bytes
@ -20,7 +20,7 @@ _str = str
class Marshaller:
"""Marshall data for Dbus."""
__slots__ = ("signature_tree", "_buf", "body")
__slots__ = ("_buf", "body", "signature_tree")
def __init__(self, signature: str, body: list[Any]) -> None:
"""Marshaller constructor."""
@ -158,25 +158,24 @@ class Marshaller:
if t == "y":
self._buf.append(body)
return 1
elif t == "u":
if t == "u":
written = self._align(4)
self._buf += PACK_UINT32(body)
return written + 4
elif t == "a":
if t == "a":
return self._write_array(body, type_)
elif t == "s" or t == "o":
if t == "s" or t == "o":
return self._write_string(body)
elif t == "v":
if t == "v":
return self._write_variant(body, type_)
elif t == "b":
if t == "b":
return self._write_boolean(body)
else:
writer, packer, size = self._writers[t]
if not writer:
written = self._align(size)
self._buf += packer(body) # type: ignore[misc]
return written + size
return writer(self, body, type_)
writer, packer, size = self._writers[t]
if not writer:
written = self._align(size)
self._buf += packer(body) # type: ignore[misc]
return written + size
return writer(self, body, type_)
def marshall(self) -> bytearray:
"""Marshalls the body into a byte array"""

View File

@ -257,30 +257,30 @@ class Unmarshaller:
"""
__slots__ = (
"_unix_fds",
"_buf",
"_buf_ustr",
"_buf_len",
"_pos",
"_stream",
"_sock",
"_message",
"_readers",
"_body_len",
"_serial",
"_header_len",
"_message_type",
"_buf",
"_buf_len",
"_buf_ustr",
"_endian",
"_flag",
"_msg_len",
"_uint32_unpack",
"_header_len",
"_int16_unpack",
"_uint16_unpack",
"_stream_reader",
"_message",
"_message_type",
"_msg_len",
"_negotiate_unix_fd",
"_pos",
"_read_complete",
"_readers",
"_serial",
"_sock",
"_sock_with_fds_reader",
"_sock_without_fds_reader",
"_negotiate_unix_fd",
"_read_complete",
"_endian",
"_stream",
"_stream_reader",
"_uint16_unpack",
"_uint32_unpack",
"_unix_fds",
)
_stream_reader: Callable[[int], bytes]
@ -383,7 +383,7 @@ class Unmarshaller:
ARRAY("i", data[: len(data) - (len(data) % MAX_UNIX_FDS_SIZE)])
)
if not msg:
raise EOFError()
raise EOFError
self._buf += msg
self._buf_len = len(self._buf)
if self._buf_len < pos:
@ -406,7 +406,7 @@ class Unmarshaller:
raise MARSHALL_STREAM_END_ERROR
raise
if not data:
raise EOFError()
raise EOFError
self._buf += data
self._buf_len = len(self._buf)
if self._buf_len >= pos:
@ -418,7 +418,7 @@ class Unmarshaller:
if data is None:
raise MARSHALL_STREAM_END_ERROR
if not data:
raise EOFError()
raise EOFError
self._buf += data
self._buf_len = len(self._buf)
if self._buf_len < pos:

View File

@ -24,7 +24,7 @@ def signature_contains_type(
st = queue.pop()
if st.token == token:
return True
elif st.token == "v":
if st.token == "v":
contains_variants = True
queue.extend(st.children)
@ -42,7 +42,7 @@ def signature_contains_type(
member.signature, [member.value], token
):
return True
elif type(member) is list:
if type(member) is list:
queue.extend(member)
elif type(member) is dict:
queue.extend(member.values())

View File

@ -190,7 +190,7 @@ class MessageBus(BaseMessageBus):
:vartype connected: bool
"""
__slots__ = ("_loop", "_auth", "_writer", "_disconnect_future", "_pending_futures")
__slots__ = ("_auth", "_disconnect_future", "_loop", "_pending_futures", "_writer")
def __init__(
self,
@ -440,7 +440,7 @@ class MessageBus(BaseMessageBus):
except asyncio.CancelledError:
pass
except Exception as e:
logging.error("unexpected exception in future", exc_info=e)
logging.exception("unexpected exception in future", exc_info=e)
def _make_method_handler(
self, interface: "ServiceInterface", method: "_Method"

View File

@ -87,8 +87,7 @@ class AuthExternal(Authenticator):
if self.negotiate_unix_fd:
self.negotiating_fds = True
return "NEGOTIATE_UNIX_FD"
else:
return "BEGIN"
return "BEGIN"
if response is _AuthResponse.AGREE_UNIX_FD:
return "BEGIN"

View File

@ -97,10 +97,9 @@ class _MessageWritableSource(_GLibSource):
if not self.bus._buffered_messages:
return GLib.SOURCE_REMOVE
else:
message = self.bus._buffered_messages.pop(0)
self.message_stream = io.BytesIO(message._marshall(False))
return GLib.SOURCE_CONTINUE
message = self.bus._buffered_messages.pop(0)
self.message_stream = io.BytesIO(message._marshall(False))
return GLib.SOURCE_CONTINUE
except BlockingIOError:
return GLib.SOURCE_CONTINUE
except Exception as e:
@ -180,7 +179,7 @@ class MessageBus(BaseMessageBus):
try:
self._process_message(msg)
except Exception as e:
logging.error(
logging.exception(
f"got unexpected error processing a message: {e}.\n{traceback.format_exc()}"
)

View File

@ -253,12 +253,12 @@ class ProxyInterface(BaseProxyInterface):
def call_notify(msg, err):
if err:
callback(None, err)
return
return None
try:
BaseProxyInterface._check_method_return(msg)
except Exception as e:
callback(None, e)
return
return None
return callback(None, None)
@ -289,7 +289,6 @@ class ProxyInterface(BaseProxyInterface):
main.run()
if reply_error:
raise reply_error
return None
snake_case = super()._to_snake_case(intr_property.name)
setattr(self, f"get_{snake_case}", property_getter)

View File

@ -568,9 +568,8 @@ class Node:
indent(elem, level + 1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
elif level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
xml = self.to_xml()
indent(xml)

View File

@ -90,20 +90,20 @@ class Message:
"""
__slots__ = (
"body",
"destination",
"path",
"error_name",
"flags",
"interface",
"member",
"message_type",
"flags",
"error_name",
"path",
"reply_serial",
"sender",
"unix_fds",
"serial",
"signature",
"signature_tree",
"body",
"serial",
"unix_fds",
)
def __init__(

View File

@ -99,24 +99,24 @@ class BaseMessageBus:
"""
__slots__ = (
"unique_name",
"_disconnected",
"_user_disconnect",
"_method_return_handlers",
"_serial",
"_user_message_handlers",
"_name_owners",
"_path_exports",
"_bus_address",
"_name_owner_match_rule",
"_match_rules",
"_high_level_client_initialized",
"_ProxyObject",
"_bus_address",
"_disconnected",
"_fd",
"_high_level_client_initialized",
"_machine_id",
"_match_rules",
"_method_return_handlers",
"_name_owner_match_rule",
"_name_owners",
"_negotiate_unix_fd",
"_path_exports",
"_serial",
"_sock",
"_stream",
"_fd",
"_user_disconnect",
"_user_message_handlers",
"unique_name",
)
def __init__(
@ -777,20 +777,17 @@ class BaseMessageBus:
) -> None:
if err:
raise err
elif msg is None:
if msg is None:
raise DBusError(
ErrorType.INTERNAL_ERROR, "invalid message type for method call", msg
)
elif (
msg.message_type == MessageType.METHOD_RETURN and msg.signature == signature
):
if msg.message_type == MessageType.METHOD_RETURN and msg.signature == signature:
return
elif msg.message_type == MessageType.ERROR:
if msg.message_type == MessageType.ERROR:
raise DBusError._from_message(msg)
else:
raise DBusError(
ErrorType.INTERNAL_ERROR, "invalid message type for method call", msg
)
raise DBusError(
ErrorType.INTERNAL_ERROR, "invalid message type for method call", msg
)
def _process_message(self, msg: _Message) -> None:
"""Process a message received from the message bus."""
@ -807,8 +804,7 @@ class BaseMessageBus:
self.send(e._as_message(msg))
handled = True
break
else:
logging.exception("A message handler raised an exception: %s", e)
logging.exception("A message handler raised an exception: %s", e)
except Exception as e:
logging.exception("A message handler raised an exception: %s", e)
if msg.message_type is MESSAGE_TYPE_CALL:
@ -926,7 +922,7 @@ class BaseMessageBus:
if msg.interface == "org.freedesktop.DBus.Peer":
if msg.member == "Ping" and msg.signature == "":
return self._default_ping_handler
elif msg.member == "GetMachineId" and msg.signature == "":
if msg.member == "GetMachineId" and msg.signature == "":
return self._default_get_machine_id_handler
if (
@ -1081,7 +1077,7 @@ class BaseMessageBus:
"getting and setting properties with an empty interface string is not supported yet",
)
elif msg.path not in self._path_exports:
if msg.path not in self._path_exports:
raise DBusError(
ErrorType.UNKNOWN_OBJECT, f'no interfaces at path: "{msg.path}"'
)
@ -1100,11 +1096,10 @@ class BaseMessageBus:
ErrorType.UNKNOWN_PROPERTY,
f'interface "{interface_name}" does not have property "{prop_name}"',
)
elif msg.member == "GetAll":
if msg.member == "GetAll":
send_reply(Message.new_method_return(msg, "a{sv}", [{}]))
return
else:
assert False
assert False
raise DBusError(
ErrorType.UNKNOWN_INTERFACE,
f'could not find an interface "{interface_name}" at path: "{msg.path}"',

View File

@ -79,11 +79,11 @@ class BaseProxyInterface:
def _check_method_return(msg: Message, signature: Optional[str] = None):
if msg.message_type == MessageType.ERROR:
raise DBusError._from_message(msg)
elif msg.message_type != MessageType.METHOD_RETURN:
if msg.message_type != MessageType.METHOD_RETURN:
raise DBusError(
ErrorType.CLIENT_ERROR, "method call didnt return a method return", msg
)
elif signature is not None and msg.signature != signature:
if signature is not None and msg.signature != signature:
raise DBusError(
ErrorType.CLIENT_ERROR,
f'method call returned unexpected signature: "{msg.signature}"',
@ -137,18 +137,21 @@ class BaseProxyInterface:
cb_result = handler.fn(*data)
if isinstance(cb_result, Coroutine):
asyncio.create_task(cb_result)
asyncio.create_task(cb_result) # noqa: RUF006
def _add_signal(self, intr_signal: intr.Signal, interface: intr.Interface) -> None:
def on_signal_fn(fn: Callable, *, unpack_variants: bool = False):
fn_signature = inspect.signature(fn)
if 0 < len(
[
par
for par in fn_signature.parameters.values()
if par.kind == inspect.Parameter.KEYWORD_ONLY
and par.default == inspect.Parameter.empty
]
if (
len(
[
par
for par in fn_signature.parameters.values()
if par.kind == inspect.Parameter.KEYWORD_ONLY
and par.default == inspect.Parameter.empty
]
)
> 0
):
raise TypeError(
"reply_notify cannot have required keyword only parameters"

View File

@ -334,16 +334,15 @@ def _real_fn_result_to_body(
out_len = len(signature_tree.types)
if result is None:
final_result = []
elif out_len == 1:
final_result = [result]
else:
if out_len == 1:
final_result = [result]
else:
result_type = type(result)
if result_type is not list and result_type is not tuple:
raise SignatureBodyMismatchError(
"Expected signal to return a list or tuple of arguments"
)
final_result = result
result_type = type(result)
if result_type is not list and result_type is not tuple:
raise SignatureBodyMismatchError(
"Expected signal to return a list or tuple of arguments"
)
final_result = result
if out_len != len(final_result):
raise SignatureBodyMismatchError(

View File

@ -21,7 +21,7 @@ class SignatureType:
"""
_tokens = "ybnqiuxtdsogavh({"
__slots__ = ("token", "token_as_int", "children", "_signature")
__slots__ = ("_signature", "children", "token", "token_as_int")
def __init__(self, token: str) -> None:
"""Init a new SignatureType."""
@ -30,7 +30,7 @@ class SignatureType:
self.children: list[SignatureType] = []
self._signature: Optional[str] = None
def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
"""Compare this type to another type or signature string."""
if type(other) is SignatureType:
return self.signature == other.signature
@ -78,7 +78,7 @@ class SignatureType:
raise InvalidSignatureError("missing type for array")
self.children.append(child)
return (self, signature)
elif token == "(":
if token == "(":
self = SignatureType("(")
signature = signature[1:]
while True:
@ -131,7 +131,7 @@ class SignatureType:
raise SignatureBodyMismatchError(
f'DBus INT16 type "n" must be Python type "int", got {type(body)}'
)
elif body > INT16_MAX or body < INT16_MIN:
if body > INT16_MAX or body < INT16_MIN:
raise SignatureBodyMismatchError(
f'DBus INT16 type "n" must be between {INT16_MIN} and {INT16_MAX}'
)
@ -143,7 +143,7 @@ class SignatureType:
raise SignatureBodyMismatchError(
f'DBus UINT16 type "q" must be Python type "int", got {type(body)}'
)
elif body > UINT16_MAX or body < UINT16_MIN:
if body > UINT16_MAX or body < UINT16_MIN:
raise SignatureBodyMismatchError(
f'DBus UINT16 type "q" must be between {UINT16_MIN} and {UINT16_MAX}'
)
@ -155,7 +155,7 @@ class SignatureType:
raise SignatureBodyMismatchError(
f'DBus INT32 type "i" must be Python type "int", got {type(body)}'
)
elif body > INT32_MAX or body < INT32_MIN:
if body > INT32_MAX or body < INT32_MIN:
raise SignatureBodyMismatchError(
f'DBus INT32 type "i" must be between {INT32_MIN} and {INT32_MAX}'
)
@ -167,7 +167,7 @@ class SignatureType:
raise SignatureBodyMismatchError(
f'DBus UINT32 type "u" must be Python type "int", got {type(body)}'
)
elif body > UINT32_MAX or body < UINT32_MIN:
if body > UINT32_MAX or body < UINT32_MIN:
raise SignatureBodyMismatchError(
f'DBus UINT32 type "u" must be between {UINT32_MIN} and {UINT32_MAX}'
)
@ -179,7 +179,7 @@ class SignatureType:
raise SignatureBodyMismatchError(
f'DBus INT64 type "x" must be Python type "int", got {type(body)}'
)
elif body > INT64_MAX or body < INT64_MIN:
if body > INT64_MAX or body < INT64_MIN:
raise SignatureBodyMismatchError(
f'DBus INT64 type "x" must be between {INT64_MIN} and {INT64_MAX}'
)
@ -191,7 +191,7 @@ class SignatureType:
raise SignatureBodyMismatchError(
f'DBus UINT64 type "t" must be Python type "int", got {type(body)}'
)
elif body > UINT64_MAX or body < UINT64_MIN:
if body > UINT64_MAX or body < UINT64_MIN:
raise SignatureBodyMismatchError(
f'DBus UINT64 type "t" must be between {UINT64_MIN} and {UINT64_MAX}'
)
@ -346,7 +346,7 @@ class SignatureTree:
(type_, signature) = SignatureType._parse_next(signature)
self.types.append(type_)
def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if type(other) is SignatureTree:
return self.signature == other.signature
return super().__eq__(other)
@ -394,7 +394,7 @@ class Variant:
:class:`SignatureBodyMismatchError` if the signature does not match the body.
"""
__slots__ = ("type", "signature", "value")
__slots__ = ("signature", "type", "value")
def __init__(
self,
@ -435,15 +435,13 @@ class Variant:
)
self.type.verify(value)
def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if type(other) is Variant:
return self.signature == other.signature and self.value == other.value
return super().__eq__(other)
def __repr__(self) -> str:
return "<dbus_fast.signature.Variant ('{}', {})>".format(
self.type.signature, self.value
)
return f"<dbus_fast.signature.Variant ('{self.type.signature}', {self.value})>"
get_signature_tree = lru_cache(maxsize=None)(SignatureTree)

View File

@ -33,7 +33,7 @@ class ExampleInterface(ServiceInterface):
array: "as", # noqa: F722
variant: "v",
dict_entries: "a{sv}", # noqa: F722
struct: "(s(s(v)))", # noqa: F722
struct: "(s(s(v)))",
) -> "asva{sv}(s(s(v)))": # noqa: F722
assert type(self) is ExampleInterface
return [array, variant, dict_entries, struct]
@ -41,17 +41,14 @@ class ExampleInterface(ServiceInterface):
@method()
def ping(self):
assert type(self) is ExampleInterface
pass
@method(name="renamed")
def original_name(self):
assert type(self) is ExampleInterface
pass
@method(disabled=True)
def not_here(self):
assert type(self) is ExampleInterface
pass
@method()
def throws_unexpected_error(self):
@ -84,7 +81,7 @@ class AsyncInterface(ServiceInterface):
array: "as", # noqa: F722
variant: "v",
dict_entries: "a{sv}", # noqa: F722
struct: "(s(s(v)))", # noqa: F722
struct: "(s(s(v)))",
) -> "asva{sv}(s(s(v)))": # noqa: F722
assert type(self) is AsyncInterface
return [array, variant, dict_entries, struct]
@ -92,17 +89,14 @@ class AsyncInterface(ServiceInterface):
@method()
async def ping(self):
assert type(self) is AsyncInterface
pass
@method(name="renamed")
async def original_name(self):
assert type(self) is AsyncInterface
pass
@method(disabled=True)
async def not_here(self):
assert type(self) is AsyncInterface
pass
@method()
async def throws_unexpected_error(self):

View File

@ -11,7 +11,7 @@ async def test_multiple_flags_in_message():
super().__init__(name)
@method()
def Echo(self, what: "s") -> "s": # noqa: F821
def Echo(self, what: "s") -> "s":
return what
bus = await MessageBus().connect()

View File

@ -9,4 +9,4 @@ def test_message_flag_map():
def test_error_type():
err = DBusError(ErrorType.FAILED, "")
assert ErrorType.FAILED == err.type
assert err.type == ErrorType.FAILED

View File

@ -132,10 +132,10 @@ def test_marshalling_with_table():
if buf != data:
print("message:")
print(json_dump(item["message"]))
print("")
print()
print("mine:")
print_buf(bytes(buf))
print("")
print()
print("theirs:")
print_buf(data)

View File

@ -19,7 +19,7 @@ def test_simple():
def test_multiple_simple():
tree = SignatureTree("sss")
assert len(tree.types) == 3
for i in range(0, 3):
for i in range(3):
assert_simple_type("s", tree.types[i])
@ -37,7 +37,7 @@ def test_array_multiple():
tree = SignatureTree("asasass")
assert len(tree.types) == 4
assert_simple_type("s", tree.types[3])
for i in range(0, 3):
for i in range(3):
array_child = tree.types[i]
assert array_child.token == "a"
assert array_child.signature == "as"
@ -65,7 +65,7 @@ def test_simple_struct():
child = tree.types[0]
assert child.signature == "(sss)"
assert len(child.children) == 3
for i in range(0, 3):
for i in range(3):
assert_simple_type("s", child.children[i])
@ -92,7 +92,7 @@ def test_nested_struct():
def test_struct_multiple():
tree = SignatureTree("(s)(s)(s)")
assert len(tree.types) == 3
for i in range(0, 3):
for i in range(3):
child = tree.types[0]
assert child.token == "("
assert child.signature == "(s)"
@ -111,7 +111,7 @@ def test_array_of_structs():
assert struct_child.token == "("
assert struct_child.signature == "(ss)"
assert len(struct_child.children) == 2
for i in range(0, 2):
for i in range(2):
assert_simple_type("s", struct_child.children[i])
@ -146,7 +146,7 @@ def test_dict_of_structs():
assert struct_child.token == "("
assert struct_child.signature == "(ss)"
assert len(struct_child.children) == 2
for i in range(0, 2):
for i in range(2):
assert_simple_type("s", struct_child.children[i])