refactor: drop redundant Windows guard on dbus re-exports#273
refactor: drop redundant Windows guard on dbus re-exports#273bluetoothbot wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #273 +/- ##
==========================================
- Coverage 99.61% 99.24% -0.38%
==========================================
Files 14 14
Lines 522 527 +5
Branches 48 48
==========================================
+ Hits 520 523 +3
- Misses 0 1 +1
- Partials 2 3 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR removes the Windows-only conditional around DBus-related re-exports so that bluetooth_adapters exposes a consistent top-level API across platforms, aligning behavior with the existing “import succeeds; usage depends on optional deps” pattern in dbus.py.
Changes:
- Unconditionally re-export DBus helpers (
BlueZDBusObjects,get_bluetooth_adapter_details,get_bluetooth_adapters,get_dbus_managed_objects) frombluetooth_adapters.__init__. - Simplify
tests/test_init.pyby removing the mirrored Windows guard and importing the DBus helpers unconditionally.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/bluetooth_adapters/__init__.py |
Removes the Windows platform gate and always re-exports DBus helpers at package top-level. |
tests/test_init.py |
Removes Windows-specific conditional imports and relies on existing skip markers for dbus-fast availability. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from .dbus import ( | ||
| BlueZDBusObjects, | ||
| get_bluetooth_adapter_details, | ||
| get_bluetooth_adapters, | ||
| get_dbus_managed_objects, | ||
| ) |
PR Review — refactor: drop redundant Windows guard on dbus re-exportsClean, minimal refactor that does exactly what the description says: drops an asymmetric Windows-only guard so the package exposes the same top-level surface on all platforms, matching the existing macOS contract. The Checklist
SummaryClean, minimal refactor that does exactly what the description says: drops an asymmetric Windows-only guard so the package exposes the same top-level surface on all platforms, matching the existing macOS contract. The Automated review by Kōane2e18a2 |
`__init__.py` previously gated the `.dbus` re-exports behind `if system() != "Windows":`. This had two problems: - Inconsistent with macOS — `dbus-fast` is also unavailable there (poetry marker is `platform_system == "Linux"`), but the macOS path imported the names fine, so the contract differed between non-Linux platforms with no functional reason. - Redundant — `dbus.py` already has its own `try/except ImportError` on `dbus_fast` that sets `MessageBus`/`BusType`/`Message`/etc. to `None`. The module imports cleanly on any platform; only calls would fail when `dbus-fast` is missing. `__all__` already listed `BlueZDBusObjects`, `get_bluetooth_adapters`, `get_bluetooth_adapter_details`, `get_dbus_managed_objects` unconditionally, so `from bluetooth_adapters import *` raised NameError on Windows. The fix aligns runtime exports with `__all__` on all platforms. `tests/test_init.py` had the same Windows guard for symmetry — also dropped; the per-test `skipif(MessageType is None ...)` guards already skip dbus-fast-dependent tests on non-Linux runners.
Rebase with requested adjustmentsBranch Changes applied
StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
e2e18a2 to
1467941
Compare
| def _ensure_dbus_fast() -> None: | ||
| """Raise a clear error if dbus_fast is not available on this platform.""" | ||
| if MessageBus is None: | ||
| raise RuntimeError( | ||
| "dbus_fast is required for DBus-based bluetooth adapter access " | ||
| "but is not installed (it is Linux-only). Install bluetooth-adapters " | ||
| "on a Linux host, or avoid calling DBus helpers on this platform." | ||
| ) |
| @@ -98,6 +111,7 @@ async def get_bluetooth_adapter_details() -> dict[str, dict[str, Any]]: | |||
|
|
|||
| async def get_dbus_managed_objects() -> dict[str, Any]: | |||
| """Return a list of bluetooth adapter with details.""" | |||
What
Drop the
if system() != "Windows":guard around the.dbusre-exports inbluetooth_adapters/__init__.py. Always importBlueZDBusObjects,get_bluetooth_adapter_details,get_bluetooth_adapters,get_dbus_managed_objectsat the top level.Why
The guard was both inconsistent and redundant:
dbus-fastisplatform_system == "Linux"inpyproject.toml, so macOS also lacks it at runtime. But the macOS path imported the names anyway, so non-Linux platforms had asymmetric contracts for no functional reason.dbus.pyalready wraps thedbus_fastimport intry/except ImportError, settingMessageBus/BusType/AuthError/Message/MessageType/unpack_variantstoNonewhen absent. The module imports cleanly on any platform; only calls would fail when dbus-fast isn't installed.The result was that
__all__listed those names unconditionally, sofrom bluetooth_adapters import *(or any direct attribute access) on Windows raisedNameError/AttributeErroreven though the module itself loaded fine.How
__init__.py: remove theplatform.system()check and the now-unusedfrom platform import systemimport; move.dbusre-exports next to the other unconditional imports.tests/test_init.py: drop the mirroringif system() != "Windows":guard and the now-unusedsystemimport. The per-testskipif(MessageType is None ...)decorators already handle dbus-fast-missing runs.Testing
poetry run pytest tests/— 51 passed, coverage still 98%.poetry run ruff check src/ tests/— clean.Quality Report
Changes: 2 files changed, 9 insertions(+), 23 deletions(-)
Code scan: clean
Tests: passed (1
PASSED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline