fix: dispatch service state change callbacks positionally#1768
fix: dispatch service state change callbacks positionally#1768bluetoothbot wants to merge 1 commit into
Conversation
Pass handler arguments to ServiceBrowser/AsyncServiceBrowser callbacks positionally instead of as keyword arguments, so callers can name the first parameter anything they like. Previously the keyword name ``zeroconf`` shadowed any ``import zeroconf`` in the user's module. The on-the-wire argument order matches the documented example signature ``(zeroconf, service_type, name, state_change)``; downstream handlers that swapped the last two parameters via keyword binding need to follow this order now.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1768 +/- ##
=======================================
Coverage 99.77% 99.77%
=======================================
Files 33 33
Lines 3509 3509
Branches 493 493
=======================================
Hits 3501 3501
Misses 5 5
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bdraco
left a comment
There was a problem hiding this comment.
nice try, but has the same problem I pointed out in the issue. This is a breaking change so we can't merge it.
PR Review — fix: dispatch service state change callbacks positionallyThe PR correctly identifies issue #1092 and the desired end state (handler parameter names should be user choice), but the implementation introduces a silent behaviour change for any downstream handler whose parameter order differs from the documented one. The diff itself demonstrates the breakage — ten in-tree handlers had to be reordered to keep tests green, all of which were previously valid because 🔴 Blocking1. Breaking change: handlers binding by keyword stop working (`src/zeroconf/_services/__init__.py`, L57-59)Switching 🟡 Important1. New test does not actually pin the reported issue (`tests/services/test_browser.py`, L966-1006)
2. `Signal` is generic — callers other than ServiceBrowser may break (`src/zeroconf/_services/__init__.py`, L57-59)
Checklist
SummaryThe PR correctly identifies issue #1092 and the desired end state (handler parameter names should be user choice), but the implementation introduces a silent behaviour change for any downstream handler whose parameter order differs from the documented one. The diff itself demonstrates the breakage — ten in-tree handlers had to be reordered to keep tests green, all of which were previously valid because To rebase specific severity levels, mention me: Automated review by Kōan4fa0b90 |
Agreed — the breaking-change concern is concrete, and the diff makes it visible: ten in-tree handlers (e.g. A few non-breaking paths that would still solve #1092:
Option 2 is probably the smallest behaviour-preserving change; option 3 is the cleanest long-term API but needs a deprecation cycle. Happy to take whichever direction you prefer — would you like me to redo this against option 2? |
|
Let's close this. This PR clearly demonstrates all options are breaking changes and documents why we can't do what the issue reporter requested |
Summary
ServiceBrowser/AsyncServiceBrowserpreviously dispatchedstate-change callbacks via
**kwargs, forcing user handlers to nametheir first parameter
zeroconf— which shadowsimport zeroconfinthe caller's module. Switch to positional dispatch so users can pick
any parameter names they like.
Fixes #1092
Changes
Signal.firenow accepts*argsand forwards positionally._ServiceBrowserBase._fire_service_state_changed_eventpasses thearguments positionally in the order
(zeroconf, service_type, name, state_change)— matching thedocumented signature in
examples/browser.pyand friends.to use the canonical positional order.
Test plan
tests/services/test_browser.py::test_service_browser_handler_callback_arg_names_independentregisters a callback whose parameters use non-default names and
verifies they are invoked correctly without a
TypeError.poetry run pytest --timeout=60passes (390 passed, 2 skipped).Compatibility note
This is a behaviour change for downstream callbacks that defined their
handler parameters in a different order than the documented one and
relied on keyword binding to sort them out. Handlers that follow the
example signature
(zeroconf, service_type, name, state_change)areunaffected.
Quality Report
Changes: 5 files changed, 61 insertions(+), 18 deletions(-)
Code scan: clean
Tests: passed (4 PASSED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline