Re: Why has __new__ been implemented as a static method?

2014-05-04 Thread Gregory Ewing
Steven D'Aprano wrote: If it were a class method, you would call it by MyBaseClass.__new__() rather than explicitly providing the cls argument. But that wouldn't be any good, because the base __new__ needs to receive the actual class being instantiated, not the class that the __new__ method

Re: Why has __new__ been implemented as a static method?

2014-05-04 Thread Steven D'Aprano
On Sun, 04 May 2014 20:03:35 +1200, Gregory Ewing wrote: Steven D'Aprano wrote: If it were a class method, you would call it by MyBaseClass.__new__() rather than explicitly providing the cls argument. But that wouldn't be any good, because the base __new__ needs to receive the actual class

Re: Why has __new__ been implemented as a static method?

2014-05-04 Thread Rotwang
On 04/05/2014 15:16, Steven D'Aprano wrote: On Sun, 04 May 2014 20:03:35 +1200, Gregory Ewing wrote: Steven D'Aprano wrote: If it were a class method, you would call it by MyBaseClass.__new__() rather than explicitly providing the cls argument. But that wouldn't be any good, because the

Re: Why has __new__ been implemented as a static method?

2014-05-04 Thread Ian Kelly
On Sun, May 4, 2014 at 8:16 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 04 May 2014 20:03:35 +1200, Gregory Ewing wrote: Steven D'Aprano wrote: If it were a class method, you would call it by MyBaseClass.__new__() rather than explicitly providing the cls argument.

Why has __new__ been implemented as a static method?

2014-05-03 Thread Jurko Gospodnetić
Hi all. I was wandering why Python implements its __new__ method as a static and not a class method? __new__ always accepts a cls parameter, which lead me to believe it was a class method. Also, implementing __new__ as a class method seems natural when thinking about __new__ as 'a

Re: Why has __new__ been implemented as a static method?

2014-05-03 Thread Steven D'Aprano
On Sat, 03 May 2014 12:37:24 +0200, Jurko Gospodnetić wrote: Hi all. I was wandering why Python implements its __new__ method as a static and not a class method? Have you read Guido's tutorial on it? https://www.python.org/download/releases/2.2.3/descrintro [quote] Factoid: __new__ is

Re: Why has __new__ been implemented as a static method?

2014-05-03 Thread Terry Reedy
On 5/3/2014 6:37 AM, Jurko Gospodnetić wrote: Hi all. I was wandering why Python implements its __new__ method as a static and not a class method? For a technical internal reason that Guido and maybe others have explained on pydev (more than once). I forget the details partly because

Re: Why has __new__ been implemented as a static method?

2014-05-03 Thread Gregory Ewing
Steven D'Aprano wrote: I'm not entirely sure what he means by upcalls, but I believe it means to call the method further up (that is, closer to the base) of the inheritance tree. I think it means this: def __new__(cls): MyBaseClass.__new__(cls) which wouldn't work with a class

Re: Why has __new__ been implemented as a static method?

2014-05-03 Thread Steven D'Aprano
On Sun, 04 May 2014 11:21:53 +1200, Gregory Ewing wrote: Steven D'Aprano wrote: I'm not entirely sure what he means by upcalls, but I believe it means to call the method further up (that is, closer to the base) of the inheritance tree. I think it means this: def __new__(cls):