When hooks are called for each steps of the SMTP call, the code check if the MISSING value is returned, which is an instance of object().
I'm curious to know why.
From my perspective, if a call to a hook returns None, the code should continue like if there were no hooks at all.
The reason behind that is if no response is returned from the hook, the server still has to return a status, and the default one is accepted by the developer.
Moreover, if a hook exists, it MUST implement the logics presents in smtp.py when no hooks exists. Let me explain:
Here's the line for HELO commands
If there are no hooks, here's what's happening:
status = await self._call_handler_hook('HELO', hostname)
if status is MISSING:
self.session.host_name = hostname
status = '250 HELP'
But as soon as I add a HELO handler, the status won't be MISSING, which means I have to implement the two consequent lines in my own code, by copy/pasting it. That's not good.
Instead, if the smtp.py code does the following:
status = await self._call_handler_hook('HELO', hostname)
# This expect that the self._call_handler_hook returns also None in case no handler was found
if status is None:
self.session.host_name = hostname
status = '250 HELP'
My handle can return None, saying "everything is good" like all hooks behave, and smtp.py will do the intended work.
But maybe I'm missing a specific reason, so I'd be curious to know.
Otherwise, happy to submit a PR if you want!
When hooks are called for each steps of the SMTP call, the code check if the
MISSINGvalue is returned, which is an instance ofobject().I'm curious to know why.
From my perspective, if a call to a hook returns
None, the code should continue like if there were no hooks at all.The reason behind that is if no response is returned from the hook, the server still has to return a status, and the default one is accepted by the developer.
Moreover, if a hook exists, it MUST implement the logics presents in smtp.py when no hooks exists. Let me explain:
Here's the line for
HELOcommandsIf there are no hooks, here's what's happening:
But as soon as I add a
HELOhandler, thestatuswon't beMISSING, which means I have to implement the two consequent lines in my own code, by copy/pasting it. That's not good.Instead, if the smtp.py code does the following:
My handle can return
None, saying "everything is good" like all hooks behave, and smtp.py will do the intended work.But maybe I'm missing a specific reason, so I'd be curious to know.
Otherwise, happy to submit a PR if you want!