Title: interface_risk: `Signal.fire(**kwargs)` loses all callback contract information · Issue #1779 · python-zeroconf/python-zeroconf · GitHub
Open Graph Title: interface_risk: `Signal.fire(**kwargs)` loses all callback contract information · Issue #1779 · python-zeroconf/python-zeroconf
X Title: interface_risk: `Signal.fire(**kwargs)` loses all callback contract information · Issue #1779 · python-zeroconf/python-zeroconf
Description: Problem Signal._handlers is typed list[Callable[..., None]], and fire(**kwargs: Any) forwards arbitrary kwargs through to each registered handler. There is no compile-time, mypy-time, or runtime check that callers are passing the keys ha...
Open Graph Description: Problem Signal._handlers is typed list[Callable[..., None]], and fire(**kwargs: Any) forwards arbitrary kwargs through to each registered handler. There is no compile-time, mypy-time, or runtime ch...
X Description: Problem Signal._handlers is typed list[Callable[..., None]], and fire(**kwargs: Any) forwards arbitrary kwargs through to each registered handler. There is no compile-time, mypy-time, or runtime ch...
Opengraph URL: https://github.com/python-zeroconf/python-zeroconf/issues/1779
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"interface_risk: `Signal.fire(**kwargs)` loses all callback contract information","articleBody":"## Problem\n\n`Signal._handlers` is typed `list[Callable[..., None]]`, and `fire(**kwargs: Any)` forwards arbitrary kwargs through to each registered handler. There is no compile-time, mypy-time, or runtime check that callers are passing the keys handlers expect (`zc`, `service_type`, `state_change`) or that handlers declare them. A typo in a fire-site key, or a handler that forgets one of the keyword args, fails only at the moment a real event happens to dispatch — which on quiet networks may be hours or days into the run. The signature also makes refactoring the dispatch contract effectively undetectable: adding or renaming a key shows up nowhere in type-checking. Because `ServiceBrowser`, `AsyncServiceBrowser`, and external consumers all wire callbacks through this mechanism, the contract is load-bearing for the whole browse API.\n\n## Why This Matters\n\nThe lack of contract masks integration bugs in third-party code that subscribes to `ServiceBrowser`, and it blocks mypy from helping anyone (including this repo) catch dispatch mismatches when the dispatch shape ever changes.\n\n## Suggested Fix\n\nLock the contract down. Define a `Protocol` describing the handler signature (`def __call__(self, zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange) -> None`), type `_handlers` as `list[that protocol]`, and change `fire` to take positional/keyword parameters that match — `def fire(self, *, zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange) -> None`. Keep backward compatibility by leaving the `register_handler` accepting `Callable[..., None]` but type-narrowing internally. Test coverage already exists for the happy paths, so the migration is mostly mechanical.\n\n## Details\n\n| | |\n|---|---|\n| **Severity** | 🟡 Medium |\n| **Category** | interface_risk |\n| **Location** | `src/zeroconf/_services/__init__.py:51-78` |\n| **Effort** | 🛠️ Moderate effort |\n\n---\n🤖 Created by Kōan from audit session\n\u003c!-- koan-audit-id: 0270740ec20a6d0e -->","author":{"url":"https://github.com/bluetoothbot","@type":"Person","name":"bluetoothbot"},"datePublished":"2026-05-26T16:28:14Z","url":"https://github.com/python-zeroconf/python-zeroconf/issues/1779"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c28768ab-9ea5-4f41-ce14-86b8300a7e9f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E8A:2BA6E:1010:14C5:6B007D37 |
| html-safe-nonce | 2328137587993278b23197e1251798c2c0d3cf22b7a3d9a183d4da6334e60a09 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RThBOjJCQTZFOjEwMTA6MTRDNTo2QjAwN0QzNyIsInZpc2l0b3JfaWQiOiI3NjI3Mzg1ODI2NjYxMzk5ODYzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bdee86997d237c220cb3db8299665e3f43b7b40665a76bdd4b2cc6668986b405 |
| hovercard-subject-tag | issue:4525792671 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-zeroconf/python-zeroconf/1779/issue_layout |
| twitter:image | https://opengraph.githubassets.com/79c169a47781539eb9030e3a05b241ee37628b50300201f737300813f5471cee/python-zeroconf/python-zeroconf/issues/1779 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/79c169a47781539eb9030e3a05b241ee37628b50300201f737300813f5471cee/python-zeroconf/python-zeroconf/issues/1779 |
| og:image:alt | Problem Signal._handlers is typed list[Callable[..., None]], and fire(**kwargs: Any) forwards arbitrary kwargs through to each registered handler. There is no compile-time, mypy-time, or runtime ch... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bluetoothbot |
| hostname | github.com |
| expected-hostname | github.com |
| None | 82c186f13e104004ab7bdb779f3195e59dd38bfde531aaa74b76470fc2462b83 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-zeroconf/python-zeroconf git https://github.com/python-zeroconf/python-zeroconf.git |
| octolytics-dimension-user_id | 120192235 |
| octolytics-dimension-user_login | python-zeroconf |
| octolytics-dimension-repository_id | 21548731 |
| octolytics-dimension-repository_nwo | python-zeroconf/python-zeroconf |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 21548731 |
| octolytics-dimension-repository_network_root_nwo | python-zeroconf/python-zeroconf |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d1bc2aa1939001689f5ce935982c10a6138f745c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width