fix: make Notifier accept configured service instances - #322
Open
pcbeingused333 wants to merge 1 commit into
Open
fix: make Notifier accept configured service instances#322pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
`Notifier.add_service` / `add_services` / `remove_service` were annotated to take a `type[Service]` and then called `service()`. Every built-in service (`Discord`, `Slack`, `Telegram`, `Resend`) requires constructor arguments, so `notifier.add_services([Discord, Telegram])` -- the form in the docstring -- raised `TypeError`, and passing an instance raised `'Discord' object is not callable`. `remove_service` was doubly broken: it instantiated a fresh object and looked for it by `==`, which never matches without a custom `__eq__`. They now take instances. `add_service` raises a clear `TypeError` if given a class by mistake, and `remove_service` removes the instance directly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GtYgwYNfJ3wHrw9xrooVoB
Contributor
Author
|
The |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Notifier.add_service/add_services/remove_serviceare annotated as takingtype[Service]and callservice():Every built-in service requires constructor arguments (
Discord(webhook_url),Resend(api_key, from_email, to_emails_raw), ...), so:notifier.add_services([Discord, Telegram])— the form in the docstring — raisesTypeError: __init__() missing 1 required positional argument.notifier.add_service(Discord(url))raisesTypeError: 'Discord' object is not callable.remove_serviceis worse: it builds a new instance and removes it by==, so it never matches an added service (no__eq__on the ABC) and always raises "not found".Notifierhas no tests and no internal callers, so nothing pinned the broken behavior.Fix
add_service/add_services/remove_servicetake configured instances.add_serviceraises a clearTypeErrorif handed a class by mistake;remove_serviceremoves the instance directly.Tests
New
tests/unit/notification/test_notifier.py— 8 cases: add/notify,add_serviceswith instances, rejecting a class, empty-notify no-op, a failing service not blocking the others, remove, remove-missing, clear. 7 of the 8 fail onmain.uv run pytest tests/unit/notificationis green (24 passed);ruff check/ruff formatclean.