{"id":200472,"date":"2020-11-14T15:55:18","date_gmt":"2020-11-14T07:55:18","guid":{"rendered":"http:\/\/4563.org\/?p=200472"},"modified":"2020-11-14T15:55:18","modified_gmt":"2020-11-14T07:55:18","slug":"%e8%bf%99%e5%8f%a5%e8%af%9d%e7%9a%84%e7%bf%bb%e8%af%91%e6%98%af%ef%bc%9fpep585","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=200472","title":{"rendered":"\u8fd9\u53e5\u8bdd\u7684\u7ffb\u8bd1\u662f\uff1f(PEP585)"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8fd9\u53e5\u8bdd\u7684\u7ffb\u8bd1\u662f\uff1f(PEP585)               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u624b\u518c\u4e2d\uff1a<br \/>class typing.Iterable(Generic[T_co])<br \/>A generic version of collections.abc.Iterable.<br \/>Deprecated since version 3.9: collections.abc.Iterable now supports []. See PEP 585.<\/p>\n<p>\u540e\u9762\u8fd9\u53e5\u6307\u7684\u662f 3.9 \u5f03\u7528 collections.abc.Iterable\uff0c\u8fd8\u662f\u5f03\u7528 typing.Iterable \uff1f<br \/>\u5b83\u7528\u9017\u53f7\u6211\u7406\u89e3\u662f\u5f03\u7528 typing.Iterable\uff0c\u7528\u5192\u53f7\u6211\u5c31\u7cca\u6d82\u4e86<\/p>\n<p>PEP585 \u4e2d\u6709\u8fd9\u53e5\uff1a<br \/>This PEP proposes to enable support for the generics syntax in all standard collections currently available in the typing module.<\/p>\n<p>PEP585 \u592a\u957f\uff0c\u82f1\u8bed\u4e0d\u4f73<\/p>\n<p>\u5176\u5b9e\u4e00\u76f4\u5bf9\u591a\u4e2a\u6a21\u5757\uff08 types, collections, typing \u7b49\uff09\u91cd\u590d\u7684\u7c7b\u578b\u5b9a\u4e49\u4e0d\u89e3\uff0c\u4e0d\u77e5\u9053\u4e0b\u9762\u8fd9\u6837\u7406\u89e3\u5bf9\u4e0d\u5bf9\uff1f<br \/>\u591a\u4e2a\u6a21\u5757\u5bf9\u4e8e\u7c7b\u578b\u7684\u5b9a\u4e49\uff0c\u4f9d\u636e PEP585 \u5f03\u7528\uff0c\u8f6c\u5230 typing \u6a21\u5757\u53bb\u5f52\u4e00\u5b9a\u4e49<\/p>\n<p>\u8fd8\u662f\u8981\u53cd\u5411\u7406\u89e3\uff0c\u800c typing \u6a21\u5757\u53ea\u7740\u91cd\u4e8e\u5904\u7406\u65b9\u6cd5\uff0c\u5b9a\u4e49\u7531\u5176\u4ed6\u6a21\u5757\u5b8c\u6210<\/p>\n<p>\u5e0c\u671b\u662f\u7528 typing \u5f52\u4e00\uff0c\u5224\u65ad\u4e00\u4e2a\u7c7b\u578b\u8981 import \u597d\u51e0\u4e2a\u6a21\u5757\u771f\u662f\u7d2f      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>10<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4280664\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aijam <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5148\u56de\u7b54\u4f60\u7684\u95ee\u9898\uff1a<br \/>&gt; \u540e\u9762\u8fd9\u53e5\u6307\u7684\u662f 3.9 \u5f03\u7528 collections.abc.Iterable\uff0c\u8fd8\u662f\u5f03\u7528 typing.Iterable?<br \/>\u5f03\u7528 typing.Iterable<br \/>&gt; \u8f6c\u5230 typing \u6a21\u5757\u53bb\u5f52\u4e00\u5b9a\u4e49<br \/>\u4e0d\u5bf9\uff0c\u662f\u53cd\u8fc7\u6765\uff1a3.9 \u4e4b\u540e typing \u91cc\u5f88\u591a\u548c\u6807\u51c6\u5e93\u672c\u6765\u5c31\u6709\u7684\u91cd\u590d\u7684\u4e1c\u897f\u88ab deprecate \u4e86<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>3.9 \u4e4b\u524d\uff0c\u4f60\u5199 list of string \u7684 type annotation \u9700\u8981\u5199&#8221;var: typing.List[str]&#8221;\u3002<br \/>3.9 \u4e4b\u540e\uff0c\u4f60\u76f4\u63a5\u7528 builtin \u7684\u7c7b\u578b list\uff0c\u53ea\u9700\u8981\u5199&#8221;var: list[str]&#8221;\uff0c\u4e0d\u9700\u8981 import typing \u3002<br \/>\u57fa\u672c\u6539\u9769\u65b9\u5411\u5c31\u662f\uff1a\u201c\u5982\u679c\u6807\u51c6\u5e93\u91cc\u6709\u8fd9\u4e2a\u7c7b\u578b\u4e86\uff0c\u5c31\u4e0d\u7528\u5728 typing \u91cc\u4e13\u95e8\u4e3a\u4e86 type annotation \u53c8\u91cd\u590d\u5b9a\u4e49\u4e00\u4e2a\u4e86\u201d\u3002\u6240\u4ee5\uff0c\u6807\u51c6\u5e93\u91cc\u672c\u6765\u5c31\u6709 collections.abc.Iterable\uff0c\u5b83\u662f list, tuple, dict \u7b49\u5171\u540c\u7684\u62bd\u8c61\u7236\u7c7b\uff0c\u6240\u4ee5\u6ca1\u5fc5\u8981\u4fdd\u7559 typing.Iterable \u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4280665\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiaolinjia <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u5224\u65ad\u7c7b\u578b\u4ece\u6765\u4e0d\u7528 typing \u7684\u6a21\u5757\uff0c\u53ea\u7528 collections.abc \u3002<br \/>\u5199\u7c7b\u578b\u6ce8\u89e3\u7684\u65f6\u5019\u624d\u7528 typing                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4280666\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiaolinjia <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             py36\uff0c\u521a\u8bd5\u4e86\u4e0b\uff0ccollections.abc \u7684 Sequence \u7b49\u5bb9\u5668\u4e0d\u80fd\u5728\u7c7b\u578b\u6ce8\u89e3\u7684\u65f6\u5019\u5199\u6210 Sequence[str]\u554a\u3002\u53ea\u6709 typing \u4e0b\u7684 Sequence \u624d\u53ef\u4ee5\u5199\u6210 Sequence[str]\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4280667\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @aijam <br \/>\u660e\u767d\u4e86<br \/>collections.abc.Iterable now supports [] \u27a1\ufe0f collections.abc.Iterable \u5f00\u59cb\u652f\u6301\u5b50\u7c7b\u578b<br \/>\u521a\u624d\u8fd8\u6ca1\u60f3\u660e\u767d\u8fd9\u4e2a\u65b9\u62ec\u53f7\u6307\u4ec0\u4e48\u2026\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4280668\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @xiaolinjia #3<br \/>\u4ee5\u7c97\u964b\u7684\u82f1\u8bed\u80fd\u529b\u7406\u89e3\uff0c\u662f\u9700\u8981\u5e26__class_getitem__()\u9b54\u672f\u65b9\u6cd5\uff0c\u800c\u8fd9\u4e2a\u662f py3.9 \u52a0\u5165\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4280669\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aijam <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @imn1 \u8fd9\u73a9\u610f\u513f\u4e0d\u53eb\u5b50\u7c7b\u578b\uff0c\u53eb parameterized generics                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4280670\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @aijam #6<br \/>\u5bf9\uff0c\u6211\u53ea\u662f\u8bcd\u7a77\uff0c\u968f\u624b\u5199\uff0c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4280671\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiaolinjia <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @imn1 \u4e0d\u77e5\u9053\u6211\u7684\u7406\u89e3\u5bf9\u4e0d\u5bf9\u3002\u6211\u73b0\u5728\u7684\u60f3\u6cd5\u662f\uff0cpy36 \u7684\u65f6\u5019\uff0c\u8fd8\u6ca1\u6709\u62bd\u8c61\u51fa__class_getitem__()\u9b54\u672f\u65b9\u6cd5\uff0c\u8fd9\u65f6\uff0c\u5982\u679c\u5728\u7c7b\u578b\u6ce8\u89e3\u4e2d\u4f7f\u7528 collections.abc.Sequence[str]\u65f6\uff0cide \u4f1a\u63d0\u793a type \u7c7b\u6ca1\u6709\u5b9a\u4e49__getitem__\u9b54\u672f\u65b9\u6cd5\uff0c\u6240\u4ee5\u6ce8\u89e3\u5931\u8d25\u3002\uff08\u56e0\u4e3a collections.abc.Sequence \u662f type \u7c7b\u7684\u5b9e\u4f8b\uff09\u3002<br \/>\u7136\u540e py37 \u7684\u65f6\u5019\uff0c\u51fa\u73b0\u4e86__class_getitem__\u9b54\u672f\u65b9\u6cd5\u8fd9\u4e2a\u63a5\u53e3\uff0c\u4f46\u662f\u5185\u7f6e\u7684\u7c7b\u578b\u6bd4\u5982 list\uff0c\u8fd8\u662f\u6ca1\u6709\u5b9a\u4e49\u4e86__class_getitem__\u8fd9\u4e2a\u65b9\u6cd5\u3002\u76f4\u5230 py39 \u7684\u65f6\u5019\uff0c\u5185\u7f6e\u7c7b\u578b list \u624d\u5b9a\u4e49\u4e86\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u4f7f\u5f97 list[str]\u4e5f\u80fd\u7528\u4e8e\u6ce8\u89e3\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4280672\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @xiaolinjia #8<br \/>\u6211\u53cd\u6b63\u611f\u89c9 py39 \u8981\u6539\u4e00\u6ce2\u4ee3\u7801\uff0c\u73b0\u5728\u6ca1\u5199 type hint \u8fd8\u597d\u8bf4\u2026\u2026<\/p>\n<p>\u53e6\u5916\u60f3\u5199\u4e2a\u7c7b\u578b\u76f8\u5173\u7684\u88c5\u9970\u5668\uff0c\u7528\u6765\u4e34\u65f6\u68c0\u67e5\u4e5f\u597d\uff0c\u5b9e\u7528\u7c7b\u578b\u8f6c\u6362\u4e5f\u597d\uff0c\u5982\u679c typing \u76f8\u5173\u5728 3.9 \u5f03\u7528\uff0c\u5c31\u8981\u91cd\u65b0\u8003\u8651\u600e\u4e48\u5199\u4e86\uff0c\u4eca\u5929\u4e3b\u8981\u60f3\u641e\u6e05\u8fd9\u4e2a\u95ee\u9898                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4280673\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiaolinjia <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @imn1 \u521a\u54a8\u8be2\u4e86\u4e0b\u5927\u4f6c\uff0c\u4ece 37 \u5f15\u5165__class_getitem__\u65b9\u6cd5\u5f00\u59cb\uff0c\u5c31\u53ef\u4ee5\u901a\u8fc7 from__future__ import annotations \u6765\u4f7f\u7528 a: list[str] = [&#8216;a&#8217;]\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u53e5\u8bdd\u7684\u7ffb\u8bd1\u662f\uff1f(PEP585) &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/200472"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=200472"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/200472\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=200472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=200472"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=200472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}