TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The Descriptor Protocol and Python Black Magic

64 pointsby avyfainabout 9 years ago

4 comments

pdknskabout 9 years ago
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 未加载
rbistolfiabout 9 years ago
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>
avyfainabout 9 years ago
Author here. Questions&#x2F;comments&#x2F;feedback are very much appreciated! AMA
评论 #11671136 未加载
voltagex_about 9 years ago
&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 未加载