<div dir="ltr"><div>This thread is derailing quickly. :-)<br><br></div>Does anyone remember why the marker pattern was invented? (That's a rhetorical question, in case you wondered. :-)<br></div><div class="gmail_extra">

<br><br><div class="gmail_quote">On Wed, Apr 16, 2014 at 11:22 AM, Zachary Ware <span dir="ltr"><<a href="mailto:zachary.ware+pyideas@gmail.com" target="_blank">zachary.ware+pyideas@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="">On Wed, Apr 16, 2014 at 12:09 PM, Yury Selivanov<br>
<<a href="mailto:yselivanov.ml@gmail.com">yselivanov.ml@gmail.com</a>> wrote:<br>
> Hello,<br>
><br>
> There is a very common pattern for creating optional arguments<br>
> when you can't use None:<br>
><br>
> _optional = object()<br>
> def foo(*, arg1='spam', arg3=None, arg4=_optional):<br>
>     if arg4 is _optional:<br>
>         # caller didn't pass *anything* for arg4<br>
>     else:<br>
>         # caller did pass some (maybe None) value for arg4<br>
><br>
> It's a bit annoying to create this marker objects, and also,<br>
> if you try to render a signature of such function, you'll get<br>
> something like:<br>
><br>
> "(*, arg1='spam', arg3=None, arg4=<object object at 0x104be7080>)"<br>
><br>
> What if we add a standard marker for this use-case:<br>
> functools.optional or inspect.Parameter.optional?<br>
<br>
</div>Has Ellipsis (...) been suggested and rejected for this use before?<br>
It's not an absolutely perfect fit, but it looks better to me:<br>
<br>
def foo(*, arg1='spam', arg3=None, arg4=...):<br>
    if arg4 is Ellipsis:<br>
        # caller didn't pass anything for arg4<br>
        ...<br>
    else:<br>
        # caller passed something, possibly None, for arg4<br>
        ...<br>
<br>
The signature would look like "(*, arg1='spam', arg3=None,<br>
arg4=Ellipsis)", unless inspect.Signature.__str__ special-cased<br>
Ellipsis to be "..." (or "<optional>" if we officially blessed<br>
Ellipsis for the purpose).<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Zach<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div>