Skip to content

Instantly share code, notes, and snippets.

@voluntas
Last active July 30, 2020 11:36
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voluntas/a8047431784173c1f0c057d6a3c619a3 to your computer and use it in GitHub Desktop.
Save voluntas/a8047431784173c1f0c057d6a3c619a3 to your computer and use it in GitHub Desktop.
pyre 使ってみた

pyre 使ってみた

OCaml で書かれた Python 型チェックツール。Facebook 製。FlowType の用な感じで使えそう。

mypy があるが、こちらはおそらく高速を売りにしている気がする。たぶん。

python/mypy: Optional static typing for Python 2 and 3 (PEP484)

URL とか

インストール

pip install pyre-check

セットアップ

pyre init

使ってみる

spam.py を作る、ちょっと型間違えてみる。

def main() -> int:
    return ""

pyre 実行してみる、ちゃんと怒られる。

$ pyre
 ƛ Waiting for server...
 ƛ Found 1 type error!
spam.py:2:4 Incompatible return type [7]: Expected `int` but got `str`.

型を str にする

def main() -> str:
    return ""

で、再度実行してみる。

$ pyre
 ƛ Waiting for server...
 ƛ No type errors found

エラーなくなった。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment