[Tutor] use of __new__

spir denis.spir at gmail.com
Fri Mar 12 14:03:25 CET 2010


On Fri, 12 Mar 2010 22:56:37 +1100
Steven D'Aprano <steve at pearwood.info> wrote:

> You might be tempted to change the first reference to Unicode to cls as 
> well, but sadly that does not work. The reason is complicated, and to 
> be honest I don't remember it, but you will probably find it by 
> googling for "python super gotchas".

Thank to your explanations, I may now have a guess on this :-)

class BASE(root):
    def __new__(cls, ...):
        ...
       obj = super(BASE, cls).__new__(cls, *args)

Let's say BASE is itself sub classed, but sub classes don't define their own __new__. How else ensure that the root class (the one actually creating new objects), is (one of) BASE's own base(s)? BASE beeing the top of a custom class tree, it's a kind of constant for its sub classes.
Is this really a flaw, or instead a logical necessity?


Denis
________________________________

la vita e estrany

spir.wikidot.com



More information about the Tutor mailing list