{"id":324759,"date":"2021-02-06T11:35:42","date_gmt":"2021-02-06T03:35:42","guid":{"rendered":"http:\/\/4563.org\/?p=324759"},"modified":"2021-02-06T11:35:42","modified_gmt":"2021-02-06T03:35:42","slug":"python-%e4%bd%bf%e7%94%a8%e9%9d%99%e6%80%81%e7%b1%bb%e5%9e%8b%e6%a0%87%e6%b3%a8%e6%97%b6%e7%9a%84%e5%be%aa%e7%8e%af%e5%af%bc%e5%85%a5%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=324759","title":{"rendered":"Python \u4f7f\u7528\u9759\u6001\u7c7b\u578b\u6807\u6ce8\u65f6\u7684\u5faa\u73af\u5bfc\u5165\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python \u4f7f\u7528\u9759\u6001\u7c7b\u578b\u6807\u6ce8\u65f6\u7684\u5faa\u73af\u5bfc\u5165\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4e00\u822c\u6765\u8bf4\uff0c\u5305\u8bbe\u8ba1\u4e2d\u505a\u62bd\u8c61\u65f6\uff0c\u4e2a\u4eba\u4e60\u60ef\u628a\u57fa\u7c7b\u62bd\u51fa\u6765\u5355\u72ec\u653e\u4e00\u4e2a\u6587\u4ef6\uff0c\u6211\u770b\u5f88\u591a\u5176\u4ed6\u4eba\u4e5f\u559c\u6b22\u8fd9\u4e48\u505a\uff0c\u6bd4\u5982\u505a\u6210\u8fd9\u6837<\/p>\n<pre><code>--\u9e1f\u7c7b\u5927\u5168     |___ base.py     |___ \u9e1f\u4eba 1.py     |___ \u9e1f\u4eba 2.py     |___ \u5de5\u5177\u7bb1.py  <\/code><\/pre>\n<p>\u5927\u6982\u8fd9\u79cd\u611f\u89c9\u3002<\/p>\n<p>\u6700\u8fd1\u5728\u505a type hints \u65f6\u9047\u5230\u4e00\u4e2a\u5faa\u73af\u5bfc\u5165\u7684\u95ee\u9898\uff0c\u5373\u6bd4\u5982\u6211\u6709\u4e00\u4e2a <code>class BaseBird:<\/code>\u5b58\u5728\u4e8e<code>base.py<\/code>\u4e2d\uff0c\u800c<code>class BirdmanOne(BaseBird)<\/code>\u5b58\u5728\u4e8e<code>\u9e1f\u4eba 1.py<\/code>\u4e2d\uff0c\u663e\u7136\u9e1f\u4eba 1.py \u9700\u8981<code>from .base import BaseBird<\/code><\/p>\n<p>\u6b63\u5e38\u60c5\u51b5\u4e0b\u6ca1\u95ee\u9898\uff0c\u5728\u8001\u7248\u672c\u91cc\u4e5f\u4e00\u76f4\u662f\u8fd9\u4e48\u5904\u7406\u7684\u3002\u4f46\u662f\u73b0\u5728\u5982\u679c\u60f3\u5f15\u5165\u7c7b\u578b\u63d0\u793a\u7279\u6027\u7684\u8bdd\uff0c\u5982\u679c<code>BaseBird<\/code>\u4e2d\u7684\u67d0\u4e2a\u65b9\u6cd5\uff0c\u6216\u8005<code>base.py<\/code>\u4e2d\u7684\u5176\u4ed6\u51fd\u6570\u3001\u65b9\u6cd5\u7684\u8f93\u5165\uff0c\u662f\u5b58\u5728\u4e8e\u5176\u4ed6\u6587\u4ef6\u4e2d\u7684\u5b50\u7c7b\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u6ca1\u529e\u6cd5\u76f4\u63a5\u4ece\u5b50\u7c7b\u5bfc\u5165\u8fd9\u79cd\u7c7b\uff0c\u56e0\u4e3a\u4f1a\u53d8\u6210\u5faa\u73af\u5f15\u7528\u3002<\/p>\n<p>\u6709\u529e\u6cd5\u89e3\u51b3\u5417\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>21<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5112193\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hareandlion <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             base.py \u4e2d\u6ca1\u6709\u62bd\u8c61\u6240\u6709\u7684\u63a5\u53e3\u5b9e\u73b0\uff1f\u90a3\u5199\u4e2a\u58f0\u660e\u4e86\u6240\u6709\u65b9\u6cd5\u7684 mixin \u4f9b\u6240\u6709\u5b50\u7c7b\u7ee7\u627f\u662f\u4e0d\u662f\u597d\u70b9\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112194\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : abersheeran <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u662f\u7684\uff0c\u8fd9\u4e2a\u95ee\u9898\u6211\u5728\u5199 Index.py \u7684\u65f6\u5019\u4e5f\u9047\u5230\u4e86\u3002\u6211\u7684\u89e3\u51b3\u65b9\u6848\u662f\u7528 PEP563 \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112195\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @hareandlion \u53ea\u662f\u4e3e\u4e86\u4e00\u4e2a\u7b80\u5355\u4f8b\u5b50\uff0c\u5b9e\u9645\u8fd8\u6709\u6bd4\u5982\u5b50\u7c7b\u4e4b\u95f4\u4e92\u76f8\u5f15\u7528\u7b49\u7b49\u60c5\u51b5\uff0c\u5b9e\u9645\u4e1a\u52a1\u4e2d\u5b8c\u5168\u89e3\u8026\u51e0\u4e4e\u4e0d\u53ef\u80fd\uff0c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112196\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @abersheeran \u6211\u770b\u4e86\u4e00\u4e0b pep563 \u6ca1\u6293\u4f4f\u91cd\u70b9\u4ed6\u60f3\u8868\u8fbe\u4ec0\u4e48\uff0c\u5927\u4f6c\u80fd\u6982\u8ff0\u4e00\u4e0b\u6709\u4ec0\u4e48\u4f5c\u7528\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112197\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Kilerd <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6709\u3002 <\/p>\n<p>from typing import TYPE_CHECKING<\/p>\n<p>if TYPE_CHECKING:<br \/> from .base import BaseBird<\/p>\n<p>https:\/\/docs.python.org\/3\/library\/typing.html#typing.TYPE_CHECKING                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112198\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @abersheeran \u624b\u673a\u4e0a\u770b\u7684\uff0c\u4e0d\u592a\u65b9\u4fbf\uff0c\u770b\u8d77\u6765\u4f3c\u4e4e\u50cf\u662f\u5f15\u5165\u4e00\u4e2a\u88ab\u52a8\u53d8\u91cf\u8df3\u8fc7\u7f16\u8bd1\u68c0\u67e5\uff1f\u7136\u540e\u5728 runtime \u4e2d\u7c7b\u578b\u63d0\u793a\u5df2\u7ecf\u88ab\u53bb\u9664\u4e86\uff0c\u6240\u4ee5\u4e0d\u4f1a\u62a5\u9519\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112199\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5f00\u673a\u6d4b\u8bd5\u4e86\u4e00\u4e0b\uff0c\u4f1a\u62a5\u9519\u554a<\/p>\n<p>https:\/\/gist.github.com\/GoodManWEN\/65464b2b3ed32c0c85d66e25002d417d <button onclick=\"lazyGist(this)\">\u00a0\u663e\u793a Gist \u4ee3\u7801\u00a0<\/button> <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112200\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : abersheeran <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @LeeReamond \u4f60\u8fd9\u4e48\u5199\u5f53\u7136\u4f1a\u62a5\u9519\u3002\u76ee\u524d\u7684 CPython\uff0ctype hint \u53ef\u662f\u4f1a\u5728\u8fd0\u884c\u65f6\u8ba1\u7b97\u7684\u3002\u8fd9\u548c\u5ba3\u79f0\u7684\u4e0d\u7b26\u3002\u624d\u6709\u4e86\u6211\u4e0a\u9762\u6240\u8bf4\u7684 PEP563 \u30023.7 \u4ee5\u4e0a\u7248\u672c\u53ef\u7528 future \u5f00\u542f\uff0c3.10 \u9ed8\u8ba4\u5f00\u542f\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112201\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 676529483 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u539f\u6765-&gt; BaseBird \u6539\u6210\u5b57\u7b26\u4e32-&gt;&#8221;BaseBird&#8221;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112202\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e5f\u53ef\u4ee5\u8f6c\u79fb\u5230 .pyi \u91cc\u9762\u53bb\uff0c1. \u5bf9\u8fd0\u884c\u65f6\u9690\u5f62\uff1b 2. \u4e0d\u62c5\u5fe7\u5faa\u73af\u5f15\u7528\u3002<br \/>\u4e0d\u597d\u7684\u5730\u65b9\u662f pydantic \u8fd9\u79cd\u4f9d\u8d56\u8fd0\u884c\u65f6 hint \u7684\u5c31\u4e0d\u884c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112203\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : popil1987 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u5f97\u8003\u8651\u4e0b\u8bbe\u8ba1\u95ee\u9898\u4e86\uff0c\u5148\u7528 typing any \u901a\u8fc7<br \/>\u5982\u679c\u975e\u5f97\u5faa\u73af\u5f15\u7528\u5c31\u5f97\u6539\u53d8\u5f15\u5165\u987a\u5e8f\uff0c\u6bd4\u5982<br \/>a.py<br \/>from .b import B<br \/>class A:<br \/> def test(self, b:B)-&gt;None:<br \/> pass<br \/>b.py<br \/>class B:<br \/> pass<br \/>from .a import A<br \/>class C:<br \/> def test(self, a:A):<br \/> pass<br \/>\u8981\u662f A \u9700\u8981 B\uff0cB \u9700\u8981 A \u90a3\u5c31\u6ca1\u529e\u6cd5\u4e86\uff0c\u6539\u8bbe\u8ba1\u5427\uff0c\u53ef\u4ee5\u591a\u7528 mixin\uff0c\u5c11\u7ee7\u627f\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112204\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : so1n <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @LeeReamond \u7b2c 10 \u884c def func(self , input:B.Bird):\u6539\u4e3a def func(self , input:&#8221;B.Bird&#8221;): \u5373\u53ef                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112205\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @popil1987 \u53ea\u662f\u8fd9\u4e48\u62bd\u8c61\u5728\u4eba\u7c7b\u903b\u8f91\u4e0a\u6bd4\u8f83\u6e05\u695a\uff0c\u53ef\u80fd\u5bf9\u7a0b\u5e8f\u6765\u8bf4\u4e0d\u6e05\u695a\uff0c\u6211\u4e0d\u592a\u61c2\u8bbe\u8ba1\u7684\u95ee\u9898\uff0cmixin \u662f\u4ec0\u4e48\u610f\u601d\uff0c\u767e\u5ea6\u641c\u4e86\u4e00\u4e0b\u6ca1\u641c\u5230                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112206\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @so1n <br \/>@no1xsyzy <br \/>@676529483 <br \/>@abersheeran <\/p>\n<p>\u8bd5\u4e86\u4e00\u4e0b\u611f\u89c9\u76ee\u524d\u8fd9\u4e9b\u65b9\u6848\u90fd\u4e0d\u884c\u3002\u6211\u5bf9\u9759\u6001\u7c7b\u578b\u7684\u671f\u671b\u6709\u4e24\u4e2a\uff0c\u5176\u4e00\u662f\u5728\u5f00\u53d1\u7684\u65f6\u5019\u53ef\u4ee5\u4f7f\u7528 IDE \u76f4\u63a5\u5bfb\u5740\u5230\u5bf9\u8c61\u7684\u76ee\u6807\u4f4d\u7f6e\uff0c\u5982\u679c\u7528\u53cc\u5f15\u53f7\u7684\u5199\u6cd5\u7684\u8bdd\u65e0\u6cd5\u5b9e\u73b0\uff0c\u5176\u4e8c\u662f\u6211\u5e0c\u671b\u80fd\u591f\u5728 runtime \u4f7f\u7528 inspect.trace \u8ffd\u8e2a\u5230\u5bf9\u8c61\uff0c\u8fd9\u6837\u53ef\u4ee5\u5728\u81ea\u52a8\u6d4b\u8bd5\u4e2d\u4f9d\u636e\u8fd9\u4e2a\u7279\u6027\u81ea\u52a8\u68c0\u67e5\u6240\u6709\u51fd\u6570\u548c\u65b9\u6cd5\u7684\u8f93\u5165\u8f93\u51fa\u662f\u5426\u7b26\u5408\u8981\u6c42\uff0c\u8ba9\u7a0b\u5e8f\u66f4\u53ef\u9760\uff0c\u5927\u6982\u7c7b\u4f3c\u4e8e\u7f16\u8bd1\u4e2d\u7684\u9759\u6001\u7c7b\u578b\u68c0\u67e5\u5427\u3002\u8fd9\u4e2a\u9700\u6c42\u7528\u53cc\u5f15\u53f7\u7684\u65b9\u5f0f\u4e5f\u65e0\u6cd5\u5b9e\u73b0\uff0c\u7528`from __future__ import annotations`\u4e5f\u65e0\u6cd5\u5b9e\u73b0\u3002<\/p>\n<p>\u76ee\u524d\u6765\u770b\u53ea\u80fd\u83b7\u53d6\u5230\u5bf9\u8c61\u7684\u5b57\u7b26\u4e32\u540d\u79f0\uff0c\u800c\u4e0d\u80fd\u76f4\u63a5\u83b7\u53d6\u5bf9\u8c61\uff0c\u800c\u8fdb\u884c isinstance \u5224\u65ad\u5fc5\u987b\u8981\u8f93\u5165\u5bf9\u8c61\uff0c\u6240\u4ee5\u4f3c\u4e4e\u65e0\u89e3\u3002\u8fd8\u6709\u4e00\u79cd\u65b9\u5f0f\u662f\u901a\u8fc7\u67d0\u79cd\u65b9\u5f0f\u8bbe\u8ba1\u91cd\u8f7d\uff0c\u5e76\u4e14\u5728\u91cd\u8f7d\u540e\u4f7f\u7528 eval()\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u7c7b\uff0c\u4f46\u4e00\u6765\u5b9e\u73b0\u6210\u672c\u8f83\u9ad8\uff0c\u4e8c\u6765 eval \u603b\u5f52\u8ba9\u4eba\u4e0d\u723d\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112207\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : so1n <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @LeeReamond \u90a3\u5c31\u9700\u8981\u5199\u4e2a\u62bd\u8c61\u7c7b\u4e86..                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112208\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @so1n \u6ca1\u542c\u61c2\uff0c\u8be6\u7ec6\u8bf4\u4e00\u4e0b\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112209\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @LeeReamond <br \/>\u65b9\u6cd5 1\uff0c\u66f4\u597d\u7684 eval \uff08 python&gt;=3.7 \uff09\uff1a<br \/>pydantic \uff08&lt;https:\/\/github.com\/samuelcolvin\/pydantic&gt;\uff09\u7528\u4e86\u4e00\u4e2a\u7c7b\u4f3c eval \u7684\u4e1c\u897f\uff1a<br \/>\/pydantic\/main.py#L757-L765<br \/>\u8fd9\u91cc\u901a\u8fc7 sys.modules[cls.__module__].__dict__ \u62ff\u5230 globals\uff0c\u7136\u540e<br \/>\/pydantic\/typing.py#L51-L68<br \/>\u5e94\u5bf9\u4e0d\u540c\u7248\u672c\u8c03\u7528 ForwardRef \u7684\u4fdd\u62a4\u65b9\u6cd5\u8fdb\u884c\u89e3\u6790\uff08\u4f46\u4ecd\u7136\u662f\u4e2a eval\uff0c\u4f60\u5b8c\u5168\u53ef\u4ee5\u5199\u51fa `a: &#8216;type(1+2)&#8217; = 5`\uff0c\u800c\u4e14\u7c7b\u578b\u68c0\u67e5\u80fd\u8fc7\uff09\u3002<\/p>\n<p>\u65b9\u6cd5 2\uff0ctyping.Protocol \uff08 python&gt;=3.8 \uff09<br \/>\u91c7\u7528 typing.Protocol\uff0c\u901a\u8fc7\u7ed3\u6784\u5b50\u7c7b\u578b\u66ff\u6362\u540d\u4e49\u5b50\u7c7b\u578b\u3002\u8fd0\u884c\u65f6\u53ef\u4ee5\u91c7\u7528 .runtime_checkable <br \/>https:\/\/docs.python.org\/zh-cn\/3\/library\/typing.html#nominal-vs-structural-subtyping \uff08\u8fd9\u662f\u6211\u7ffb\u8bd1\u7684\uff0c\u5c31\u653e\u4e2d\u6587\u6587\u6863\u4e86\uff09<br \/>\uff08 Go \u7684 interface \u5c31\u662f\u7ed3\u6784\u5b50\u7c7b\u578b\uff0c\u81f3\u4e8e Ponylang \u5219\u540c\u65f6\u5b9e\u73b0\u4e86\u7ed3\u6784\u5b50\u7c7b\u578b\uff08 interface \uff09\u548c\u540d\u4e49\u5b50\u7c7b\u578b\uff08 trait \uff09\uff09<\/p>\n<p>\u65b9\u6cd5 3\uff0c\u63a7\u5236\u53cd\u8f6c\uff08\u65e0\u8981\u6c42\uff09<br \/>\u9700\u8981\u52a8\u4ee3\u7801\u7ed3\u6784\u3002<br \/>\u5148\u89e3\u91ca\u4e0b mixin \u548c abc\uff1a<br \/>mixin \u662f\u4e00\u79cd\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u53ef\u4ee5\u53c2\u8003 Ponylang\/rust \u7684 trait\uff0c\u628a\u4e00\u4e9b\u975e\u5173\u952e\u4f9d\u8d56\u7684\u65b9\u6cd5\u4ece\u57fa\u7c7b\u91cc\u5265\u79bb\u51fa\u53bb\uff0c\u6700\u540e\u4f9d\u8d56\u7ed3\u6784\u4f1a\u5f62\u6210\u4e00\u4e2a Diamond \u3002<br \/>\u62bd\u8c61\u7c7b\u662f\u6307\u6807\u51c6\u5e93 abc \u6a21\u5757\uff0c\u628a\u6700\u57fa\u7840\u7684\u8981\u6c42\u63d0\u53d6\u51fa\u6765\u53ef\u4ee5\u5728\u7c7b\u578b\u91cc\u7559\u6d1e\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112210\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy \u611f\u8c22\u56de\u590d\uff0c\u6709\u65f6\u95f4\u7814\u7a76\u4e00\u4e0b\u3002\u5173\u4e8e mixin \u548c\u62bd\u8c61\u7c7b\uff0c\u6211\u4e0d\u4f1a ponylang \u548c rust\uff0c\u6240\u4ee5\u65e0\u6cd5\u7406\u89e3\u4f60\u63d0\u4f9b\u7684 mixin \u7684\u4f8b\u5b50\u3002\u62bd\u8c61\u7c7b\u8fd9\u4e2a\u529f\u80fd\u5bf9\u4e8e\u4ee3\u7801\u590d\u7528\u4e0d\u662f\u5f88\u707e\u96be\u4e48\uff0c\u56e0\u4e3a\u672c\u8eab\u7ee7\u627f\u5c31\u662f\u5e0c\u671b\u53ef\u4ee5\u590d\u7528\u57fa\u7c7b\u7684\u4ee3\u7801\uff0c\u5982\u679c\u6bcf\u4e2a\u5b50\u7c7b\u5fc5\u987b\u91cd\u65b0\u5b9e\u73b0\u4e00\u904d\u7684\u8bdd\u611f\u89c9\u5f88\u7d2f\u8d58\u554a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112211\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy \u6211\u6d4b\u8bd5\u4e86\u4e00\u4e0b\u65b9\u6cd5 1\uff0c\u6211\u6ca1\u592a\u770b\u61c2 https:\/\/github.com\/samuelcolvin\/pydantic\/blob\/master\/pydantic\/typing.py#L51-L68 \u8fd9\u4e00\u6bb5\u600e\u4e48\u7528 eval \u5b9e\u73b0\u7684\u5b57\u7b26\u4e32\u5230\u5b9e\u4f8b\u7684\u8f6c\u6362\uff0c\u4e0d\u662f\u5f88\u7406\u89e3\u4e3a\u4ec0\u4e48 from typing import _eval_type \u4e4b\u540e\uff0c_eval_type \u5c31\u53d8\u6210\u4e86 ForwardRef \u7684\u65b9\u6cd5\uff0c\u6211\u81ea\u5df1\u8fd9\u4e48\u8c03\u7528\u6ca1\u6709\u6210\u529f\uff0c\u6240\u4ee5\u4e0d\u662f\u5f88\u7406\u89e3 sys.modules[cls.__module__].__dict__\u62ff\u5230\u7684 globals \u600e\u4e48\u8f6c\u5316\uff0c\u6211\u81ea\u5df1\u4ece\u4e2d\u6ca1\u6cd5\u63d0\u53d6\u60f3\u8981\u7684\u4fe1\u606f\uff0c\u867d\u7136 runtime \u5f53\u4e2d\u8fd9\u53e5\u6267\u884c\u5df2\u7ecf\u5728\u5bfc\u5165\u6240\u6709\u5e93\u4e4b\u540e\uff0c\u4f46\u4ecd\u7136\u53ea\u80fd\u62ff\u5230\u76f8\u5bf9\u8be5\u6587\u4ef6\u7684 globals                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112212\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy \u611f\u8c22\uff0c\u5df2\u7ecf\u89e3\u51b3                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5112213\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : maocat <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @LeeReamond \u4f60\u597d\uff0c\u4f60\u662f\u600e\u4e48\u89e3\u51b3\u7684\u5462                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python \u4f7f\u7528\u9759\u6001\u7c7b\u578b\u6807\u6ce8\u65f6\u7684&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\/324759"}],"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=324759"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/324759\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324759"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}