{"id":306,"date":"2019-10-25T13:34:23","date_gmt":"2019-10-25T04:34:23","guid":{"rendered":"http:\/\/localhost:8000\/?p=306"},"modified":"2021-01-23T12:24:41","modified_gmt":"2021-01-23T03:24:41","slug":"python-typing","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2019\/10\/python-typing.html","title":{"rendered":"python\u306e\u578b\u30d2\u30f3\u30c8"},"content":{"rendered":"

python\u306f\u52d5\u7684\u578b\u4ed8\u3051\u8a00\u8a9e\u3067\u3059\u304c\u3001\u30d0\u30fc\u30b8\u30e7\u30f33.5\u3067\u578b\u30d2\u30f3\u30c8<\/b>\u304c\u5c0e\u5165\u3055\u308c\u305f\u3053\u3068\u306b\u3088\u308a\u3001\u9759\u7684\u578b\u4ed8\u3051\u8a00\u8a9e\u3063\u307d\u304f\u958b\u767a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n

\u305f\u3060\u3057\u3001\u516c\u5f0f\u30da\u30fc\u30b8<\/a> \u306b\u3082\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u3044\u3066\u3042\u308b\u3088\u3046\u306b\u3001<\/p>\n

\n

Python \u30e9\u30f3\u30bf\u30a4\u30e0\u306f\u3001\u95a2\u6570\u3084\u5909\u6570\u306e\u578b\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u5f37\u5236\u3057\u307e\u305b\u3093\u3002 \u578b\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306f\u3001\u578b\u30c1\u30a7\u30c3\u30ab\u30fc\u3001IDE\u3001linter\u306a\u3069\u306e\u30b5\u30fc\u30c9\u30d1\u30fc\u30c6\u30a3\u30fc\u30c4\u30fc\u30eb\u3067\u4f7f\u308f\u308c\u307e\u3059\u3002<\/p>\n<\/blockquote>\n

\u578b\u30d2\u30f3\u30c8\u81ea\u4f53\u306f\u3042\u304f\u307e\u3067\u30b3\u30e1\u30f3\u30c8\u306e\u5ef6\u9577\u3067\u3042\u308a\u52d5\u4f5c\u306b\u306f\u4e00\u5207\u5f71\u97ff\u3092\u4e0e\u3048\u307e\u305b\u3093\u3002\u578b\u30c1\u30a7\u30c3\u30ab\u30fc\u3001IDE\u3001linter\u306a\u3069\u306e\u30c4\u30fc\u30eb\u306b\u3088\u3063\u3066\u5229\u7528\u3055\u308c\u307e\u3059\u3002<\/p>\n

\u578b\u30d2\u30f3\u30c8\u306e\u5c0e\u5165\u306b\u95a2\u3057\u3066\u306f\u30e1\u30ea\u30c3\u30c8\u3057\u304b\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u5c0e\u5165\u3057\u3066\u5feb\u9069\u306apython life\u3092\u304a\u304f\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n

\u578b\u30d2\u30f3\u30c8\u306e\u30e1\u30ea\u30c3\u30c8<\/h2>\n

\u578b\u30d2\u30f3\u30c8\u3092\u5c0e\u5165\u3059\u308b\u30e1\u30ea\u30c3\u30c8\u306f3\u3064\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n

    \n
  1. \u30b3\u30fc\u30c9\u30c1\u30a7\u30c3\u30af<\/li>\n
  2. \u5165\u529b\u5019\u88dc\u306e\u8868\u793a<\/li>\n
  3. \u53ef\u8aad\u6027\u5411\u4e0a<\/li>\n<\/ol>\n

    \u30b3\u30fc\u30c9\u30c1\u30a7\u30c3\u30af<\/h3>\n

    \u578b\u30d2\u30f3\u30c8\u306e\u6700\u5927\u306e\u30e1\u30ea\u30c3\u30c8\u306f\u9759\u7684\u578b\u30c1\u30a7\u30c3\u30af\u3060\u3068\u601d\u3044\u307e\u3059\u3002
    \nIDE\u3067\u5b9f\u88c5\u4e2d\u306b\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u6642\u306b\u578b\u30d2\u30f3\u30c8\u3067\u6307\u5b9a\u3057\u305f\u578b\u3068\u7570\u306a\u308b\u578b\u306e\u5024\u304c\u30a2\u30b5\u30a4\u30f3\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306b\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002
    \n\"\"<\/p>\n

    \u305f\u3060\u3057\u3001VS\u30b3\u30fc\u30c9\u306e\u5834\u5408\u3001\u30b3\u30fc\u30c9\u30c1\u30a7\u30c3\u30af\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u307e\u307e\u3067\u306f\u3084\u3063\u3066\u304f\u308c\u306a\u3044\u306e\u3067\u3001mypy\u3092\u5c0e\u5165\u3057\u3001settings.json\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n

    {\n    "python.linting.lintOnSave": true,\n    "python.linting.mypyEnabled": true,\n}<\/code><\/pre>\n

    \u306a\u304a\u3001\u30b3\u30fc\u30c9\u30c1\u30a7\u30c3\u30af\u30c4\u30fc\u30eb\u3092\u3044\u308c\u306a\u3044\u5834\u5408\u3001\u5b9f\u88c5\u304c\u6b63\u3057\u304f\u3066\u578b\u30d2\u30f3\u30c8\u3060\u3051\u304c\u9593\u9055\u3063\u3066\u3044\u308b\u72b6\u614b\u3067\u30b3\u30fc\u30c9\u304ccommit\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
    \n\u305d\u306e\u5834\u5408\u3001\u578b\u30d2\u30f3\u30c8\u306f\u8aa4\u89e3\u3092\u751f\u3080\u3060\u3051\u306a\u306e\u3067\u3001\u53ef\u8aad\u6027\u304c\u4e0b\u304c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u578b\u30d2\u30f3\u30c8\u3092\u5c0e\u5165\u3059\u308b\u306e\u3067\u308c\u3070\u3001\u30b3\u30fc\u30c9\u30c1\u30a7\u30c3\u30af\u30c4\u30fc\u30eb\u306f\u5fc5\u305a\u5c0e\u5165\u3057\u305f\u65b9\u304c\u3044\u3044\u3067\u3059\u3002<\/p>\n

    \u5165\u529b\u5019\u88dc\u306e\u8868\u793a<\/h3>\n

    \u578b\u30d2\u30f3\u30c8\u3092\u6307\u5b9a\u3057\u3066\u304f\u3053\u3068\u3067\u3001IDE\u304c\u5909\u6570\u306e\u578b\u3092\u8a8d\u8b58\u3057\u3001\u305d\u306e\u5909\u6570\u304c\u6301\u3063\u3066\u3044\u308b\u30d7\u30ed\u30d1\u30c6\u30a3\u3084\u95a2\u6570\u3092\u30d7\u30eb\u30c0\u30a6\u30f3\u3067\u8868\u793a\u3057\u3066\u304f\u308c\u307e\u3059\u3002
    \nVS\u30b3\u30fc\u30c9\u3092\u4f7f\u3063\u3066\u3044\u308c\u3070\u3001\u3053\u308c\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u3084\u3063\u3066\u304f\u308c\u308b\u3088\u3046\u3067\u3059\u3002
    \n\"\"<\/p>\n

    \u53ef\u8aad\u6027\u5411\u4e0a<\/h3>\n

    \u6b63\u3057\u304f\u578b\u30d2\u30f3\u30c8\u3092\u66f8\u3044\u3066\u3042\u308b\u5834\u5408\u3001\u53ef\u8aad\u6027\u304c\u8457\u3057\u304f\u5411\u4e0a\u3057\u307e\u3059\u3002<\/p>\n

    \u4f8b\u3048\u3070\u3001<\/p>\n

    books = library.get_books_by_name('xxx')<\/code><\/pre>\n

    \u3068\u3042\u3063\u305f\u3057\u3066\u3001books\u306b\u5165\u308b\u578b\u304cList\u306a\u306e\u304bSet\u306a\u306e\u304b\u3001\u4f55\u306e\u30ea\u30b9\u30c8\u306a\u306e\u304b\u3092\u660e\u78ba\u306b\u5224\u65ad\u3067\u304d\u308b\u4eba\u306f\u3044\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001<\/p>\n

    books: Set[Book] = library.get_books_by_name('xxx')<\/code><\/pre>\n

    \u3068\u306a\u3063\u3066\u3044\u308c\u3070\u3001\u8ab0\u304c\u307f\u3066\u3082Book\u306eSet\u3067\u3042\u308b\u3053\u3068\u304c\u7406\u89e3\u3067\u304d\u307e\u3059\u3002<\/p>\n

    \u540c\u69d8\u306b\u3001<\/p>\n

    @dataclasses.dataclass(frozen=True)\nclass Liblary:\n    all_books\n    def get_books_by_name(self, name):\n        return set(filter(lambda b:b.name == name, self.all_books))<\/code><\/pre>\n

    \u3068\u3042\u3063\u305f\u3068\u3057\u3066\u3001\u3053\u306ename<\/code>\u306e\u578b\u304c\u4f55\u306a\u306e\u304b\u3001\u623b\u308a\u5024\u304cList\u306a\u306e\u304bSet\u306a\u306e\u304b\u3001Set\u3060\u3068\u3057\u3066\u3069\u306e\u578b\u306eSet\u304c\u8fd4\u308b\u306e\u304b\u3092\u6b63\u78ba\u306b\u5224\u65ad\u3059\u308b\u306e\u306f\u56f0\u96e3\u3060\u3068\u601d\u3044\u307e\u3059\u304c\u3001<\/p>\n

    @dataclasses.dataclass(frozen=True)\nclass Liblary:\n    all_books: Set[Book]\n    def get_books_by_name(self, name: str) -> Set[Book]:\n        return set(filter(lambda b:b.name == name, self.all_books))<\/code><\/pre>\n

    \u3068\u306a\u3063\u3066\u3044\u308c\u3070\u3001\u5f15\u6570\u3082\u623b\u308a\u5024\u3082\u8ab0\u306e\u76ee\u304b\u3089\u898b\u3066\u3082\u660e\u78ba\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

    \u578b\u30d2\u30f3\u30c8\u3092\u66f8\u3044\u3066\u6b32\u3057\u3044\u5834\u6240<\/h2>\n

    \u3082\u3068\u3082\u3068Java\u306e\u4e16\u754c\u304b\u3089\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u30b9\u30bf\u30fc\u30c8\u3057\u305f\u81ea\u5206\u3068\u3057\u3066\u306f\u3001\u5168\u3066\u306e\u7b87\u6240\u306b\u578b\u30d2\u30f3\u30c8\u3092\u66f8\u304f\u306e\u304c\u4e00\u756a\u3044\u3044\u3068\u611f\u3058\u307e\u3059\u304c\u3001kotlin\u3084scala\u306a\u3069\u578b\u63a8\u8ad6\u304c\u5c0e\u5165\u3055\u308c\u3066\u3044\u308b\u8a00\u8a9e\u3082\u3042\u308a\u5168\u3066\u306b\u578b\u3092\u8a18\u8f09\u3059\u308b\u3053\u3068\u304c\u30c7\u30e1\u30ea\u30c3\u30c8\u306b\u611f\u3058\u308b\u3053\u3068\u3082\u7406\u89e3\u3067\u304d\u307e\u3059\u3002
    \n\u4f8b\u3048\u3070\u3001\u4f55\u304b\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046\u5834\u5408\u306b\u3001\u9014\u4e2d\u6bb5\u968e\u3067\u751f\u6210\u3059\u308b\u5909\u6570\u306e\u578b\u3092\u5168\u90e8\u8abf\u3079\u4e0a\u3052\u308b\u306e\u306f\u3042\u307e\u308a\u610f\u5473\u304c\u306a\u3044\u6c17\u3082\u3057\u307e\u3059\u3002
    \n\u306a\u306e\u3067\u3001\u7d76\u5bfe\u306b\u578b\u30d2\u30f3\u30c8\u3092\u66f8\u3044\u3066\u6b32\u3057\u3044\u5834\u6240\u3060\u3051\u8a18\u8f09\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n