Stop calling super() on handlers that have no base implementation #6
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/nickname-in-use"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The bot crashed on startup the moment its nick was taken:
Root cause
The
irclibrary dispatches these hooks withgetattr(self, "on_" + event.type, do_nothing). They are optional callbacks, not overrides — neitherSingleServerIRCBotnorSimpleIRCClientdefines any of them:There was nothing to call up to. The library's own bookkeeping lives in separately registered
_on_*global handlers, which run regardless of these methods.on_disconnecthad the identical bug and would have crashed on the first disconnect — it simply had not fired yet.The fix
Both
super()calls removed. Since nothing upstream handlesnicknameinuse, the retry has to be ours or the bot sits unregistered forever. It now:Why the tests missed it
No test had ever invoked these handlers. A call to a nonexistent base method is only reachable at runtime, so it could only fail against a live server.
The new
tests/test_bot_handlers.pycloses that gap two ways: it runs everyon_*hookSlopBotdefines, and it asserts that none of the four server-lifecycle hooks exist on any base class — so a futuresuper()call fails in CI rather than on connect.Confirmed by reinstating both bugs:
on_nicknameinusecrashon_disconnectcrash385 tests, up from 361.
The bot crashed on startup the moment its nick was taken: File "bot.py", line 83, in on_nicknameinuse super().on_nicknameinuse(connection, event) AttributeError: 'super' object has no attribute 'on_nicknameinuse' Root cause: the irc library dispatches these hooks with getattr(self, "on_" + event.type, do_nothing). They are optional callbacks, not overrides -- SingleServerIRCBot and SimpleIRCClient define none of on_welcome, on_join, on_disconnect or on_nicknameinuse. There was nothing to call up to. The library's own bookkeeping lives in separately registered _on_* global handlers, which run regardless. on_disconnect had the identical bug and would have crashed on the first disconnect; it had simply not fired yet. Because nothing upstream handles nicknameinuse, the retry has to be ours or the bot sits unregistered forever. It now appends an underscore, trimming first so an already-maximal nick still changes, and gives up after 5 attempts rather than looping. on_welcome resets the counter and warns when the nick it landed on is not the configured one. Why the tests missed it: no test had ever invoked these handlers, so a call to a nonexistent base method could only fail against a live server. The new tests run every on_* hook SlopBot defines, and assert that none of the four server-lifecycle hooks exist on any base class. Reinstating the original bug now fails 7 tests; the latent on_disconnect one fails 3. Tests: 385, up from 361. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>