On 24/06/2020 20:38, Guido van Rossum wrote:
Everyone,

If you've commented and you're worried you haven't been heard, please add your issue *concisely* to this new thread. Note that the following issues are already open and will be responded to separately; please don't bother commenting on these until we've done so:

- Alternative spellings for '|'
- Whether to add an 'else' clause (and how to indent it)
- A different token for wildcards instead of '_'
- What to do about the footgun of 'case foo' vs. 'case .foo'

(Note that the last two could be combined, e.g. '?foo' or 'foo?' to mark a variable binding and '?' for a wildcard.)

(Prefatory remarks:  I am sure you get a lot of questions to which the answer is basically "Read the PEP".  I myself have been guilty in this regard.  But I fear this is inevitable when the PEP is so long and there is so much new stuff to absorb.  Apologies if this is yet another one.)

_First question_: Sometimes no action is needed after a case clause.  If the Django example had been written

if (
    isinstance(value, (list, tuple)) and
    len(value) > 1 and
    isinstance(value[-1], (Promise, str))
):
    *value, label = value
else:
    label = key.replace('_', ' ').title()

the replacement code would/could be

match value:
    case [*value, label := (Promise() | str())] if value:
        pass
    case _:
        label = key.replace('_', ' ').title()

AFAICS the PEP does not *explicitly* state that the 'pass' line is necessary 
(is it?), i.e. that the block following `case` cannot (or can?) be empty.
The term `block` is not defined in the PEP, or in 
https://docs.python.org/3/reference/grammar.html.
But an empty block following a line ending in `:` would AFAIK be unprecedented 
in Python.  I think it is worth clarifiying this.

_Second question_: in the above example replacement, if `case _:` does not bind 
to `_`, does that mean that the following line will not work?
Is this one of the "two bugs" that Mark Shannon alluded to?  (I have read every 
message in the threads and I don't remember them being spelt out.)
And I'm curious what the other one is (is it binding to a variable `v`?).

Best wishes
Rob Cliffe

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/DTEZNGGDKXWMQBYPNJZFWP4KBDWWVOAZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to