Can someone explain Python hasattr/delattr on a method attribute?
<p>I've got a bug caused by some weird behavior. I might be fundamentally missing something about the semantics of function attributes. Or it may be a bug. I'm on </p>

<pre><code>$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
[GCC 4.5.2] on linux2
</code></pre>

<p>First I define a class, and add an attribute to one of its methods.</p>

<pre><code>&gt;&gt;&gt; class Foo(object):
...    def bar(self):
...        pass
...    bar.xyzzy = 'magic'
...
</code></pre>

<p>Now I can see that exists on <code>Foo.bar</code></p>

<pre><code>&gt;&gt;&gt; hasattr(Foo.bar, 'xyzzy')
True
</code></pre>

<p>And I can retrieve it.</p>

<pre><code>&gt;&gt;&gt; Foo.bar.xyzzy
'magic'

&gt;&gt;&gt; getattr(Foo.bar, 'xyzzy')
'magic'
</code></pre>

<p>But I can't delete it.</p>

<pre><code>&gt;&gt;&gt; del Foo.bar.xyzzy
Traceback (most recent call last):
   ...
AttributeError: 'instancemethod' object has no attribute 'xyzzy'

&gt;&gt;&gt; delattr(Foo.bar, 'xyzzy')
Traceback (most recent call last):
   ...
AttributeError: 'instancemethod' object has no attribute 'xyzzy'
</code></pre>

<p>Any ideas why? I assume it is something to do with the fact that <code>Foo.bar</code> is being reported as an 'instancemethod' here, rather than an unbound method if you just ask what <code>Foo.bar</code> is. But I'm not sure if it is an expected side-effect, if I'm misunderstanding something, or if there's a bug.</p>
