2019.06.17 22:00+09:00
python3.8にmypyをインストール。まだmasterじゃないとインストールできない。
$ git clone --recurse-submodules https://github.com/python/mypy.git
$ cd mypy
$ python3.8 setup.py install
だがしかし、python3.8は from typing import Literal で、 mypyはまだ from typing_extensions import Literal でないとimportできない。
literaltypes1.py
from typing import Literal
def spam(mode: Literal["egg", "hum"]):
print(mode)
if __name__ == '__main__':
spam("salad")
$ python3.8 literaltypes1.py
salad
literaltypes2.py
from typing_extensions import Literal
def spam(mode: Literal["egg", "hum"]):
print(mode)
if __name__ == '__main__':
spam("salad")
$ mypy literaltypes2.py
literaltypes2.py:7: error: Argument 1 to "spam" has incompatible type "Literal['salad']"; expected "Union[Literal['egg'], Literal['hum']]"