[Python-ideas] 'default' keyword argument for max(), min()
denis.spir at free.fr
Wed Apr 15 21:24:05 CEST 2009
Le Wed, 15 Apr 2009 11:17:07 -0700,
"Raymond Hettinger" <python at rcn.com> s'exprima ainsi:
> [Adam Atlas]
> >I propose adding a "default" keyword argument to max() and min(),
> > which provides a value to return in the event that an empty iterable
> > is passed.
> Could you write your proposal out in pure python so
> we can see how it interacts with the key-keyword
> argument and how it works when the number of
> positional arguments is not one.
> Will min(default=0) still return a TypeError?
> Will min(1, 2, default=0) return 0 or 1?
> Will min([1,2], default=0) return 1? # different from min([0,1,2])
While there has been quick support for the proposal, I do not find it as obvious as it seems.
I see an issue based on a possible confusion about "default". Actually, "default" is the name of a proposed optional argument for min() and max() -- but this does not mean this argument, that happens to be called "default", itself has an evident default value ;-)
Even for min(), I really doubt 0 is a right choice as "default"'s default value; while for max() it's imo obviously wrong.
The issue as I see it is related to the fact that python does not allow optional arguments without default values -- which in most cases is not problematic. But here I would like an hypothetical
min(s, optional default)
While this is not possible, I support the proposal with None as default value for "default", instead of an often wrong choice.
Maybe another word as "default" would help avoid confusion, too.
la vita e estrany
More information about the Python-ideas