<div dir="ltr">I hear where you're coming from but I really don't think we should do this. If you don't have the right expectation already it's hard to guess what it means. I would much rather spend effort on a proper matching statement.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 12, 2018 at 2:54 AM, Serhiy Storchaka <span dir="ltr"><<a href="mailto:storchaka@gmail.com" target="_blank">storchaka@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yet one crazy idea. What if allow default values for targets in multi-target assignment?<br>
<br>
    >>> (a, b=0) = (1, 2)<br>
    >>> a, b<br>
    (1, 2)<br>
    >>> (a, b=0) = (1,)<br>
    >>> a, b<br>
    (1, 0)<br>
    >>> (a, b=0) = ()<br>
    Traceback (most recent call last):<br>
      File "<stdin>", line 1, in <module><br>
    ValueError: not enough values to unpack (expected at least 1, got 0)<br>
    >>> (a, b=0) = (1, 2, 3)<br>
    Traceback (most recent call last):<br>
      File "<stdin>", line 1, in <module><br>
    ValueError: too many values to unpack (expected at most 2)<br>
<br>
Currently you need either explicitly check the length of the right-hand part (if it is a sequence and not an arbitrary iterator),<br>
<br>
    if len(c) == 1:<br>
        a, = c<br>
        b = 0<br>
    elif len(c) == 2:<br>
        a, b = c<br>
    else:<br>
        raise TypeError<br>
<br>
or use an intermediate function:<br>
<br>
    def f(a, b=0):<br>
        return a, b<br>
    a, b = f(*c)<br>
<br>
The latter can be written as an ugly one-liner:<br>
<br>
    a, b = (lambda a, b=0: (a, b))(*c)<br>
<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>