Conflicting needs for __init__ method

Mark Dickinson dickinsm at gmail.com
Mon Jan 15 11:18:09 EST 2007


On Jan 14, 7:49 pm, "Ziga Seilnacht" <ziga.seilna... at gmail.com> wrote:
> Mark wrote:[a lot of valid, but long concerns about types that return
>  an object of their own type from some of their methods]
>
> I think that the best solution is to use an alternative constructor
> in your arithmetic methods. That way users don't have to learn about
> two different factories for the same type of objects. It also helps
> with subclassing, because users have to override only a single method
> if they want the results of arithmetic operations to be of their own
> type.

Aha.  I was wondering whether __new__ might appear in the solution
somewhere, but couldn't figure out how that would work;  I'd previously
only ever used it for its advertised purpose of subclassing immutable
types.

> Hope this helps,

It helps a lot.  Thank you.

Mark




More information about the Python-list mailing list