AttributeError in "with" statement (3.2.2)

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Dec 16 20:26:24 EST 2011


On Fri, 16 Dec 2011 17:05:57 -0500, Terry Reedy wrote:

> On 12/16/2011 4:22 AM, Steven D'Aprano wrote:
>> On Thu, 15 Dec 2011 19:39:17 -0500, Terry Reedy wrote: [...]
>>
>> After reading your post, I think I have worked out where our
>> disagreement lines: you think that bound methods and instance methods
>> are not the same thing,
> 
> Do you agree that an unbound method and a bound method are different? 

"Are different" or "are different types"?

Bound and unbound methods in Python 2 are the same type. They are 
different in the sense that one is effectively a curry of the other, but 
they are implemented as a single type. So presumably the difference is a 
bound method has a slot filled and an unbound method doesn't, or some 
other implementation detail.

In Python 3, unbound methods don't exist.


> In
> Python, as indicated by the glossary entry, an unspecified 'method' is
> usually meant to be an unbound method. 

I think you are badly confused here. The glossary talks about calling 
methods as an attribute of an instance, e.g. instance.method(), and the 
method receiving the instance as the first argument. That's a bound 
method, not unbound. How do you conclude that this indicates that an 
unspecified "method" is unbound?

Your conclusion is especially nonsensical because unbound methods don't 
exist in Python 3 -- you're alleging that the usual meaning of "method" 
is something which no longer exists in the language!

    method
        A function which is defined inside a class body. If called as 
        an attribute of an instance of that class, the method will get
        the instance object as its first argument (which is usually
        called self). See function and nested scope.

http://docs.python.org/glossary.html


> It is am important distinction
> and I do not see why you insist on confusing the two.

It is not an important distinction, and I am not confusing the two. Bound 
or unbound, it is still an instance method.


>> and that a function defined inside a class is different from a function
>> outside of a class.
> 
> That, and your repetition of the same claim further on, is a insulting
> lie.

If you can't assume I'm carrying on this discussion in good faith, then  
we have a serious problem. This is not like you Terry -- I've been 
reading your posts for many years, and you're not usually so obstreperous.


> Def statements always create functions. I have known that for 14 years
> since the first day I started with Python. I have never thought
> differently. If you actually think that I have, you are wrong.

I'm glad to hear it. But nevertheless you have made statements (which I 
quoted, and you deleted from your reply) that suggest the opposite. If I 
have misinterpreted them, or if you had worded them badly, there's no 
need to attribute malice to me. Calling me a liar for something said in 
good faith and which I prefixed with "I think" is simply not cool.



-- 
Steven



More information about the Python-list mailing list