{"id":1796,"date":"2017-05-24T11:00:38","date_gmt":"2017-05-24T02:00:38","guid":{"rendered":"https:\/\/blog.ymyzk.com\/?p=1796"},"modified":"2017-05-24T00:46:24","modified_gmt":"2017-05-23T15:46:24","slug":"mypy-reveal-type","status":"publish","type":"post","link":"https:\/\/blog.ymyzk.com\/2017\/05\/mypy-reveal-type\/","title":{"rendered":"mypy \u306e reveal_type \u3067\u578b\u60c5\u5831\u3092\u30c7\u30d0\u30c3\u30b0\u3059\u308b"},"content":{"rendered":"

Python \u306e\u9759\u7684\u578b\u691c\u67fb\u5668\u306e mypy \u3092\u4f7f\u3046\u3068\uff0c\u578b\u30d2\u30f3\u30c8\u3092\u8a18\u8ff0\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7c21\u5358\u306b\u9759\u7684\u306b\u578b\u691c\u67fb\u3092\u884c\u3046\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\uff0e\u3057\u304b\u3057\uff0c\u4e88\u60f3\u5916\u306e\u3068\u3053\u308d\u3067\u578b\u30a8\u30e9\u30fc\u304c\u51fa\u305f\u3068\u304d\u306a\u3069\uff0c\u306a\u305c\u305d\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u51fa\u305f\u306e\u304b\u308f\u304b\u3089\u306a\u3044\u3068\u304d\u3082\u3042\u308a\u307e\u3059\uff0e<\/p>\n

reveal_type<\/code> \u3092\u4f7f\u3046\u3068\uff0c\u30d7\u30ed\u30b0\u30e9\u30e0\u4e2d\u306e\u5f0f\u304c mypy \u306b\u3088\u3063\u3066\u3069\u306e\u3088\u3046\u306a\u578b\u304c\u3064\u3051\u3089\u308c\u3066\u3044\u308b\u304b\u3092\u7c21\u5358\u306b\u30c7\u30d0\u30c3\u30b0\u51fa\u529b\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\uff0e\u3053\u308c\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\uff0c\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u304c\u66f8\u3044\u305f\u578b\u30d2\u30f3\u30c8\u304c\u9593\u9055\u3063\u3066\u3044\u308b\u306e\u304b\uff0ctypeshed \u306e\u30b9\u30bf\u30d6\u30d5\u30a1\u30a4\u30eb\u304c\u9593\u9055\u3063\u3066\u3044\u308b\u306e\u304b\uff0c\u306f\u305f\u307e\u305f mypy \u81ea\u4f53\u306e\u30d0\u30b0\u306a\u306e\u304b\u304c\u5c11\u3057\u5206\u304b\u308a\u3084\u3059\u304f\u306a\u308a\u307e\u3059\uff0e<\/p>\n

<\/p>\n

\u4f7f\u3044\u65b9<\/h2>\n

reveal_type<\/code> \u306e\u4f7f\u3044\u65b9\u306f mypy \u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\u306b\u63b2\u8f09\u3055\u308c\u3066\u3044\u307e\u3059\uff0e\u4ee5\u4e0b\u306e\u3088\u3046\u306b\uff0c\u30d7\u30ed\u30b0\u30e9\u30e0\u4e2d\u3067\u578b\u3092\u78ba\u8a8d\u3057\u305f\u3044\u5f0f\u306b\u3064\u3044\u3066\uff0creveal_type(\u578b\u3092\u78ba\u8a8d\u3057\u305f\u3044\u5f0f)<\/code> \u3068\u66f8\u304d\u307e\u3059\uff0e<\/p>\n

x = 1\r\ny = \"hello\"\r\nxy = x, y\r\n\r\ndef f(x: int):\r\n    return x\r\n\r\nreveal_type(x)\r\nreveal_type(y)\r\nreveal_type(xy)\r\nreveal_type(f)<\/code><\/pre>\n

mypy \u3067\u3053\u306e\u30b3\u30fc\u30c9\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3068\uff0c\u30ed\u30b0\u306b\u578b\u60c5\u5831\u304c\u51fa\u529b\u3055\u308c\u307e\u3059\uff0e<\/p>\n

$ mypy reveal.py\r\nreveal.py:8: error: Revealed type is 'builtins.int'\r\nreveal.py:9: error: Revealed type is 'builtins.str'\r\nreveal.py:10: error: Revealed type is 'Tuple[builtins.int, builtins.str]'\r\nreveal.py:11: error: Revealed type is 'def (x: builtins.int) -> Any'<\/code><\/pre>\n

 <\/p>\n","protected":false},"excerpt":{"rendered":"

Python \u306e\u9759\u7684\u578b\u691c\u67fb\u5668\u306e mypy \u3092\u4f7f\u3046\u3068\uff0c\u578b\u30d2\u30f3\u30c8\u3092\u8a18\u8ff0\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7c21\u5358\u306b\u9759\u7684\u306b\u578b\u691c\u67fb\u3092\u884c\u3046\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\uff0e\u3057\u304b\u3057\uff0c\u4e88\u60f3\u5916\u306e\u3068\u3053\u308d\u3067\u578b\u30a8\u30e9\u30fc\u304c\u51fa\u305f\u3068\u304d\u306a\u3069\uff0c\u306a\u305c\u305d\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u51fa\u305f\u306e\u304b\u308f\u304b\u3089\u306a\u3044\u3068\u304d\u3082\u3042\u308a […]<\/p>\n","protected":false},"author":2,"featured_media":1799,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[108,15,96],"_links":{"self":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/1796"}],"collection":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/comments?post=1796"}],"version-history":[{"count":2,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/1796\/revisions"}],"predecessor-version":[{"id":1798,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/1796\/revisions\/1798"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/media\/1799"}],"wp:attachment":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/media?parent=1796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/categories?post=1796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/tags?post=1796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}