TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The Descriptor Protocol and Python Black Magic

64 点作者 avyfain大约 9 年前

4 条评论

pdknsk大约 9 年前
A related, albeit simpler, Python quirk.<p><pre><code> &gt;&gt;&gt; a = 100 &gt;&gt;&gt; b = 100 &gt;&gt;&gt; a is b True &gt;&gt;&gt; a = 1000 &gt;&gt;&gt; b = 1000 &gt;&gt;&gt; a is b False</code></pre>
评论 #11671253 未加载
rbistolfi大约 9 年前
Note that the descriptor protocol itself is not causing this behavior. What actually happens here is that functions are descriptors (they implement __get__()) that generate the instancemethod object on attribute access. More info here: <a href="https:&#x2F;&#x2F;wiki.python.org&#x2F;moin&#x2F;FromFunctionToMethod" rel="nofollow">https:&#x2F;&#x2F;wiki.python.org&#x2F;moin&#x2F;FromFunctionToMethod</a>
avyfain大约 9 年前
Author here. Questions&#x2F;comments&#x2F;feedback are very much appreciated! AMA
评论 #11671136 未加载
voltagex_大约 9 年前
&gt;In 3, this distinction between bound and unbound doesn’t exist, but strangely, the docs for Python 3 are not up to date<p>Is there a place for raising documentation bugs?
评论 #11672118 未加载