Skip to content

Instantly share code, notes, and snippets.

@kitak
Last active October 21, 2016 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitak/b43859e12700376d9a19fdcc3b789b1d to your computer and use it in GitHub Desktop.
Save kitak/b43859e12700376d9a19fdcc3b789b1d to your computer and use it in GitHub Desktop.
mypy メモ
  • http://qiita.com/icoxfog417/items/c17eb042f4735b7924a3 を読んだので試してみた
  • JSでいうFlowみたいな立ち位置
  • lintだけしてくれる
  • pip install mypy-lang で入る(mypyだと別のパッケージが入るから気をつけてね)
  • 使い方は mypy hoge.py みたいなかんじでシンプル
  • こんなかんじのあえてありえないコードを書いて試した
class Human:
    def __init__(self, name: str) -> None:
        self.name = name

    def hello(self) -> str:
        return 'Hello ' + self.name

def greeting(name: str) -> Human:
    human = Human(name)
    return human

human = greeting('kitak')
print(human.hello())
  • 型の書き方を言語仕様で決めてくれているのは安心感がある
  • JSとかFlowやめたくなった時にどうしようという気持ちになる(型抜きで出力するツールを書けばよさそうな気もするけれど)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment