[Python-ideas] proto-PEP: Fixing Non-constant Default Arguments
Chris Rebert
cvrebert at gmail.com
Wed Jan 31 03:05:13 CET 2007
Roman Susi wrote:
> Chris Rebert wrote:
>> Jim Jewett wrote:
>>
>>> On 1/28/07, Chris Rebert <cvrebert at gmail.com> wrote:
>
> /skip/
>
>>>> def foo(bar=new baz):
>>>> #code
>>> This would be less bad.
>>>
>>> That said, I fear many new programmers would fail to understand when
>>> they needed new and when they didn't, so that in practice, it would be
>>> just optional random noise.
>>
>> This is part of the reason I'm trying to avoid adding new syntax.
>> However, I assert that at least 'new' is clearer than the' x=None; if x
>
> But if you are concerned with the current None, there could be some
> other, new False value serving the same need, like:
>
> def foo(x, y, z, bar=Missing, qux=Missing):
> if baz is Missing:
> baz = []
> #code
>
> or even:
>
> def foo(x, y, z, bar=, qux=):
> if baz is Missing:
> baz = []
> #code
>
> at least, it doesn't require decorators, is backward compatible
> (hopefully no grammar conflicts in there), reads as English.
Those examples are only slightly better than using None. The convention
of using None to indicate use of a mutable/non-constant default value is
about as clear as your examples.
The point wasn't that None wasn't descriptive/specific enough, but
rather why have to write the 'bar=None' and then the 'if bar is None'
when 'bar=[]' could be sufficient? Also, this indicates exactly what the
default value is, as opposed to None/Missing, which is just an opaque
indicator for 'some mutable/non-constant default value'.
Thus, I see no need for 'Missing' or a similar constant.
- Chris Rebert
More information about the Python-ideas
mailing list