Re: static, class and instance methods

2016-10-07 Thread Steve D'Aprano
On Fri, 7 Oct 2016 04:01 pm, ast wrote: > > "Gregory Ewing" a écrit dans le message de > news:e5mgi9fp1b...@mid.individual.net... >> Lawrence D’Oliveiro wrote: >>> >>> Every function is already a descriptor. >> >> Which you can see with a simple experiment: >> >> >>> def f(self): >> ... print("

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

2016-10-06 Thread ast
"Gregory Ewing" a écrit dans le message de news:e5mgi9fp1b...@mid.individual.net... Lawrence D’Oliveiro wrote: Every function is already a descriptor. Which you can see with a simple experiment: >>> def f(self): ... print("self =", self) ... I thought yesterday that every thing was cle

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

2016-10-06 Thread ast
"Steve D'Aprano" a écrit dans le message de news:57f6673a$0$1598$c3e8da3$54964...@news.astraweb.com... 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

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

2016-10-06 Thread Steve D'Aprano
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 proto

Re: static, class and instance methods

2016-10-06 Thread Steve D'Aprano
On Thu, 6 Oct 2016 05:53 pm, ast wrote: [...] > * For instance methods, there is no decorator: > > def funct2(self, a, b): > ... > > self is automatically filled with the instance when we call > funct2 from an instance and not filled if funct2 is called from > a class. > But there is no decorato

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

2016-10-06 Thread Peter Otten
ast wrote: > > "Lawrence D’Oliveiro" a écrit dans le message de > news:f5314bdd-a98f-4a16-b546-bd8efe4dd...@googlegroups.com... >> On Thursday, October 6, 2016 at 7:54:08 PM UTC+13, ast wrote: >>> But there is no decorator, why ? Is python doing the conversion >>> of funct2 to a descriptor itsel

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

2016-10-06 Thread ast
"Lawrence D’Oliveiro" a écrit dans le message de news:f5314bdd-a98f-4a16-b546-bd8efe4dd...@googlegroups.com... On Thursday, October 6, 2016 at 7:54:08 PM UTC+13, ast wrote: But there is no decorator, why ? Is python doing the conversion of funct2 to a descriptor itself, behind the scene ? E

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

2016-10-06 Thread Gregory Ewing
Lawrence D’Oliveiro wrote: Every function is already a descriptor. Which you can see with a simple experiment: >>> def f(self): ... print("self =", self) ... >>> g = f.__get__(17, None) >>> g >>> g() self = 17 -- Greg -- https://mail.python.org/mailman/listinfo/python-list

static, class and instance methods

2016-10-05 Thread ast
Hello, In a class there are three possible types of methods, the static methods, the class methods and the instance methods * Class methods are decorated, eg: @classmethod def func(cls, a, b): ... I read that the decorator tranforms 'func' as a descriptor, and when this descriptor is read, it