PEP for an unrestricted __init__ ?!
holger krekel
pyth at devel.trillke.net
Thu Apr 18 18:20:07 EDT 2002
On Thu, Apr 18, 2002 at 01:59:19PM -0700, Jimmy Retzlaff wrote:
> > holger krekel [mailto:pyth at devel.trillke.net] writes:
> > I'd would like to know if anybody thinks it's
> > worthwile to start a formal PEP
> ...
> > to bring full factory-pattern power to the __init__
> > constructor of a class.
>
> I believe that's exactly what __new__ is for in new-style classes. See
> PEP 285 for an example of __new__ usage for exactly this purpose (in
> the
> Specification section).
good pointer. It seems like PEP 253 is the original PEP
for the use described in PEP 285. Guido's time machine :-)
But __new__ or __init__ still restrict you to return instances
of their respective class? This does sound rather sane,
but i imagined some other uses for an unrestricted __init__ (or __new__)
such as making functions-objects a special case of classes:
def func(args):
"compute some stuff
return result
and
class func:
def __init__(self, args):
"compute some stuff"
return result
start to look very similar. This opens up some interesting uses,
like letting the functions "constructor" decide if it has enough
arguments and
returning a function instance (with some prebound arguments)
otherwise. Currently functions are always singletons...
but i might be terribly on the wrong path ...
holger
More information about the Python-list
mailing list