Hooks returning None should make smtp.py behave like nothing happened.
- 主要言語
- Python
- スター
- 373
- フォーク
- 105
- 平均マージ
- 4分
- マージ済み PR(30日)
- 2
説明
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](https://github.com/aio-libs/aiosmtpd/blob/master/aiosmtpd/smtp.py#L338)
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!
コントリビューションガイド
評価
この issue はまだ評価されていません。