Skip to content

Commit c789ca9

Browse files
committed
fix: accept and discard extra kwargs in Signal.fire for back compat
1 parent b127121 commit c789ca9

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

src/zeroconf/_services/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import enum
2626
from collections.abc import Callable
27-
from typing import TYPE_CHECKING
27+
from typing import TYPE_CHECKING, Any
2828

2929
if TYPE_CHECKING:
3030
from .._core import Zeroconf
@@ -61,6 +61,7 @@ def fire(
6161
service_type: str,
6262
name: str,
6363
state_change: ServiceStateChange,
64+
**kwargs: Any,
6465
) -> None:
6566
for h in self._handlers[:]:
6667
h(

tests/test_services.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,28 @@ def handler(
303303
]
304304

305305

306-
def test_signal_fire_rejects_unknown_kwarg():
307-
"""Signal.fire rejects keyword args outside the contract."""
306+
def test_signal_fire_discards_unknown_kwarg():
307+
"""Signal.fire accepts extra keyword args and does not forward them."""
308308
signal = r.Signal()
309-
signal.registration_interface.register_handler(lambda **_: None)
309+
captured: list[dict[str, Any]] = []
310+
signal.registration_interface.register_handler(lambda **kw: captured.append(kw))
310311

311-
with pytest.raises(TypeError, match="unexpected keyword argument"):
312-
signal.fire(
313-
zeroconf=None, # type: ignore[arg-type]
314-
service_type="_http._tcp.local.",
315-
name="x._http._tcp.local.",
316-
state_change=r.ServiceStateChange.Added,
317-
bogus=1, # type: ignore[call-arg]
318-
)
312+
signal.fire(
313+
zeroconf=None, # type: ignore[arg-type]
314+
service_type="_http._tcp.local.",
315+
name="x._http._tcp.local.",
316+
state_change=r.ServiceStateChange.Added,
317+
bogus=1,
318+
)
319+
320+
assert captured == [
321+
{
322+
"zeroconf": None,
323+
"service_type": "_http._tcp.local.",
324+
"name": "x._http._tcp.local.",
325+
"state_change": r.ServiceStateChange.Added,
326+
}
327+
]
319328

320329

321330
def test_signal_fire_rejects_positional_args():

0 commit comments

Comments
 (0)