alias method definitions / syntactic sugar suggestion
R. David Murray
rdmurray at bitdance.com
Wed Mar 18 21:31:51 CET 2009
Terry Reedy <tjreedy at udel.edu> wrote:
> andrew cooke wrote:
> > [sorry for dup terry; prev not to list]
> > Terry Reedy wrote:
> >> @alias('justAsFantastic')
> >> def someFantasticMethod(args): ...
> > does this exist? i read the previous post and thought "i think a
> > decorator could do that", but i haven't written one.
> Not that I know of -- an exercise for the reader.
> Now that I think about it more, injecting a name into what will become
> the class dict is not trivial. I assume that one of the 'get the
> caller's namespace' tricks would work, but have not tried it.
> > the reason i ask is that for 3->2 backwards compatability i need to do
> > this in a couple of places. it would be nice to have:
> > @alias('__nonzero__')
> > def __bool__(self):
> > and even better(?) if it could depend on python version!
> > or maybe there's another solution to the __bool__ problem above? (there's
> > also next methods, can't think of anything else off the top of my head)
What we really need is a 3to2 script. This has been suggested
before and even worked on, but as far as I can see there currently
is no such tool.
R. David Murray http://www.bitdance.com
More information about the Python-list