static, class and instance methods (Reposting On Python-List Prohibited)

Steve D'Aprano steve+python at pearwood.info
Thu Oct 6 11:01:13 EDT 2016


On Thu, 6 Oct 2016 08:03 pm, ast wrote:

> Consider this function:
> 
> def add(a, b):
>     return a+b
> 
> You say that a function is always stored as
> a descriptor object, so when I execute
> 
> sum = f(4, 6)
> 
> from which class it is supposed to come from ?


It doesn't. The descriptor protocol only gets called by classes, so when you
call a function directly, the special __get__ method isn't used.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list