Conflicting needs for __init__ method

Mark Dickinson dickinsm at gmail.com
Tue Jan 16 16:52:56 CET 2007


On Jan 16, 10:25 am, "Mark Dickinson" <dicki... at gmail.com> wrote:

> that is, I was working from the following two assumptions:
>
> (1) *Every* time a Rational is created, __init__ must eventually be
> called, and
> (2) The user of the class expects to call Rational() to create
> rationals.

(with apologies for replying to myself)

I'm still not being careful.  The assumptions should be these:

(1) Any creation of a Rational instance must eventually go through
Rational().
(2) A call to Rational() eventually results in a call to __init__.
(3) The user of the class expects to call Rational() to create
rationals.

There you are:  three flawed assumptions for the price of two! (1)
fails because __new__ provides an alternative, (2) could easily become
untrue by changing the metaclass, and (3)---well, who knows what the
user expects?

Right.  Now that I've thoroughly analyzed my own stupidity, things are
much clearer.  Thank you to all who replied.

Mark




More information about the Python-list mailing list