Returning other instance from __init__

Paul Boddie paul at
Thu Mar 15 16:02:25 CET 2007

On 15 Mar, 15:50, a... at (Alex Martelli) wrote:
> Paul Boddie <p... at> wrote:
> > Call me a traditionalist, but why wouldn't a factory function be good
> > enough?
> That depends on whether you need name C1 to refer to a class, or not.


> If you want name C1 to be usable outside this module as a class (to
> subclass it, use with isinstance or issubclass, be available to an IDE's
> classbrowser or other means of introspection including pydoc, etc), then
> making name C1 refer to a function instead would not work.

True. I can easily buy the argument about wanting to subclass C1,
although you'd always have the real class available somewhere as well.
For things like IDEs, class browsers and so on, I think more work
needs to be done to make these things more "aware" - it sounds like
they expect a more rigid language (like Java), but I do have some
awareness of why it's tempting to let them operate on their current
level of introspection.

> > Or perhaps seeing more special methods and decorators just puts me in
> > a grumpy mood. ;-) For me, the power of Python is derived from being
> > able to do things like making callables "constructors" whilst
> > providing some illusion that C1 (in this case) is a class.
> For me, OTOH, it's not just smoke and mirrors (or as you say
> "illusion"), there's also plenty of real power, and __new__ is part of
> that.

Oh, I like the illusion! The illusion is what makes Python so
powerful, after all.


More information about the Python-list mailing list