Skip to content

Instantly share code, notes, and snippets.

@tsuyukimakoto
Last active June 17, 2019 14:03
Show Gist options
  • Select an option

  • Save tsuyukimakoto/3b6d0f13d20af5ad1fa6443b390b4acd to your computer and use it in GitHub Desktop.

Select an option

Save tsuyukimakoto/3b6d0f13d20af5ad1fa6443b390b4acd to your computer and use it in GitHub Desktop.

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できない。

python実行

literaltypes1.py

from typing import Literal

def spam(mode: Literal["egg", "hum"]):
    print(mode)

if __name__ == '__main__':
    spam("salad")
$ python3.8 literaltypes1.py
salad

mypyでチェック

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']]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment