feat(service): allow specifying D-Bus signatures via decorator arguments#743
feat(service): allow specifying D-Bus signatures via decorator arguments#743bluetoothbot wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #743 +/- ##
==========================================
+ Coverage 92.19% 92.31% +0.11%
==========================================
Files 29 29
Lines 3614 3643 +29
Branches 621 635 +14
==========================================
+ Hits 3332 3363 +31
+ Misses 165 164 -1
+ Partials 117 116 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Added |
There was a problem hiding this comment.
Pull request overview
This PR enhances the dbus_fast.service decorators to allow specifying D-Bus signatures directly in decorator arguments (for methods, signals, and properties), enabling users to keep regular Python type hints (or no type hints) without relying on D-Bus signature annotations.
Changes:
- Add
in_signature/out_signatureparameters to@dbus_methodandsignatureto@dbus_signal/@dbus_property, bypassing annotation parsing when provided. - Adjust service member construction to build introspection data from explicit decorator signatures (including IN-arg names for methods).
- Add new unit/integration tests covering decorator-provided signatures, validation, introspection XML output, and a session-bus round trip.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/dbus_fast/service.py |
Adds decorator arguments for explicit signatures and updates _Method, _Signal, and _Property construction/validation paths accordingly. |
tests/service/test_decorator_signatures.py |
Adds tests validating explicit decorator signatures for methods/signals/properties, including introspection XML and an async round-trip call. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for i, type_ in enumerate(get_signature_tree(in_signature).types): | ||
| arg_name = param_names[i] if i < len(param_names) else None | ||
| in_args.append(intr.Arg(type_, intr.ArgDirection.IN, arg_name)) |
| bus1.disconnect() | ||
| bus2.disconnect() |
PR Review — feat(service): allow specifying D-Bus signatures via decorator argumentsSolid, well-scoped feature that closely mirrors the upstream python-dbus-next design — but a recreation-path edge case breaks its primary use case under PEP 563. Strengths worth calling out:
Needs attention before merge:
Note: the quality report flags tests as FAILED while the PR claims green — worth confirming locally whether that's the known flaky 🟡 Important
1. PEP 563 + `-> int` getter crashes the setter recreation path
|
Add in_signature/out_signature to @dbus_method, signature to @dbus_signal and @dbus_property. When given, the parameter/return annotations are not inspected, so callers can use ordinary Python type hints (keeping mypy and editors happy) without the typing.Annotated/DBusSignature wrappers. Closes Bluetooth-Devices#438
Rebase with requested adjustmentsBranch Changes applied
StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
be07359 to
43ba5f7
Compare
What
Let
@dbus_method,@dbus_signal, and@dbus_propertytake the D-Bus signature directly as a decorator argument, instead of only via parameter/return annotations.Why
Closes #438. Today the only way to declare a member's signature is through annotations — either bare string literals (
val: 's') ortyping.Annotated[..., DBusSignature(...)]. The bare-string form makes mypy/pyright flag every annotation, and theAnnotatedform is verbose. Some callers also just don't want type hints at all. The maintainer flagged this as "a reasonable change" on the issue; this mirrors the originalpython-dbus-nextdesign (altdesktop/python-dbus-next#111).How
in_signature/out_signatureondbus_method,signatureondbus_signal/dbus_property. When provided, the corresponding annotation is not inspected; when omitted, behaviour is unchanged._Propertyneeded care:property.setter()recreates the instance through__init__without the options, so the getter's plain type hint can't be parsed there. The explicit signature is stashed inoptionsand restored inset_options()(whichsetter()calls), with the getter-annotation parse made non-fatal on that recreation path..pxdchange (the new args live on__init__/decorator defs, not the cdef field layout).Testing
tests/service/test_decorator_signatures.py: unit coverage for method/signal/property signatures + introspection arg names/XML, type validation, and a real session-bus round trip (method call + property Get).371 passed) and theREQUIRE_CYTHON=1compiled leg (service is inTO_CYTHONIZE).Quality Report
Changes: 12 files changed, 328 insertions(+), 269 deletions(-)
Code scan: clean
Tests: failed (FAILED)
Branch hygiene: clean
Generated by Kōan