aio-libs / aio-libs/aiosmtpd

Add mypy/static type annotations

オープン
#128 コメント 11 件 リアクション 3 件 担当者 0 名 GitHub で見る
in progress tech-debt
主要言語
Python
スター
373
フォーク
105
平均マージ
4分
マージ済み PR(30日)
2

説明

It seems reasonable to add type annotations since aiosmtpd is a Python 3 application/library and type annotations can provide better documentation to users. With the use of a tool like [mypy](http://mypy.readthedocs.io/en/latest/index.html), those assertions can even be tested.

We'll pretty quickly run into problems though since our `Handler` classes are duck typed, and mypy does not yet support structural typing. Meaning, examples such as `Controller.__init__()`'s `handler` argument does not have to be a subclass of anything; it simply needs to support some methods. Handlers are even weirder than straight up duck types too, because `handle_*()` methods are optional.

Similarly, `SMTP` methods `smtp_*()` are optional too.

Some things that *might* help include:

* [PEP 544](https://www.python.org/dev/peps/pep-0544/) defines "Protocols" that can be used to structurally type arguments;
* Techniques such as those described in [this blog post](https://trm.io/2017/01/29/structural-subtyping-python.html);
* Just using an [Any](https://docs.python.org/3/library/typing.html#typing.Any) type for the duck typed arguments;
* Require that handlers derive from a common base class. I don't like this solution much as it was essentially rejected for an earlier PR, and it would be an API change requiring a major version number bump

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。