Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20761 > unrolled thread

Optional arguments syntax (was Re: sum() requires number, not simply __add__)

Started byChris Angelico <rosuav@gmail.com>
First post2012-02-24 09:11 +1100
Last post2012-02-24 09:11 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Optional arguments syntax (was Re: sum() requires number, not simply __add__) Chris Angelico <rosuav@gmail.com> - 2012-02-24 09:11 +1100

#20761 — Optional arguments syntax (was Re: sum() requires number, not simply __add__)

FromChris Angelico <rosuav@gmail.com>
Date2012-02-24 09:11 +1100
SubjectOptional arguments syntax (was Re: sum() requires number, not simply __add__)
Message-ID<mailman.98.1330035113.3037.python-list@python.org>
On Fri, Feb 24, 2012 at 9:09 AM, Arnaud Delobelle <arnodel@gmail.com> wrote:
> On 23 February 2012 22:04, Chris Angelico <rosuav@gmail.com> wrote:
>> On Fri, Feb 24, 2012 at 8:59 AM, Arnaud Delobelle <arnodel@gmail.com> wrote:
>>> def sum(iterable, start=_sentinel, _sentinel=_sentinel):
>>
>> Is this a reason for Python to introduce a new syntax, such as:
>>
>> def foo(blah, optional=del):
>>    if optional is del: print("No argument was provided")
>>
>> Basically, 'del' is treated like a unique non-providable object, only
>> possible in an argument list and only if the argument was omitted. No
>> more proliferation of individual sentinels... what do you think?
>
> The problem with these proposals is to avoid the leakage of 'del'.
> Here you could do:
>
> def get_del(x=del):
>    return x
>
> And then you're in trouble again.

Yep; what I was thinking was that this would be a magic token that, if
used in any expression other than "is del", would decay to some other
object such as 0 or None. Otherwise, yeah, there's no difference
between that and any other global sentinel.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web