Proposal: min(None, x) and max(None, x) return x

holger krekel pyth at devel.trillke.net
Fri Nov 22 12:11:24 EST 2002


Dave Brueck wrote:
> On Fri, 22 Nov 2002, Eric Brunel wrote:
> 
> > So I told myself: wouldn't it be great if max(None, x) or min(None, x) 
> > always simply returned x? So I could just write:
> > 
> > xMax = None
> > for -whatever-:
> >   -big calculation leading to a value of x-
> >   xMax = max(x, xMax)
> > 
> > Okay, it only saves 3 lines, but I personally find it quite natural...
> > In addition, today, min(None, x) and max(None, x) work, but have strange 
> > results: as far as I can see, min(None, x) is always None and max(None, x) 
> > is always x, but this behaviour isn't documented.
> > 
> > Opinions anyone?
> 
> Sure! Write two functions, and put them in your sitecustomize.py file. No 
> PEPs to write, no patches to submit, no battles to win, and you get all 
> the functionality you want _today_.

This reasoning is a bit broad and could be applied to many new ideas.
Which doesn't mean it's wrong :-)

Personally, i'd prefer returning the non-None parameter in case one
param is None. But probably it's not worth breaking backward 
compatilibity. 

    holger




More information about the Python-list mailing list