Hi Rob,
You are right: the grammar should probably read `suite` rather
than `block` (i.e. the `pass` is necessary). Thanks for catching
this!
As for the second question, I assume there might be a slight
oversight on your part. The last line in the example replaces the
string `"_"` rather than the variable `_`. The not-binding of `_`
thus has no influence on the last line.
I think I will leave it for Mark himself to name the two bugs rather
than start a guessing game. However, in an earlier version we had
left out the `if value` for the first case, accidentally translating
the `len(value) > 1` as a `len(value) >= 1` instead.
Kind regards,
Tobias
Quoting Rob Cliffe via Python-Dev <python-dev@python.org>:
[...]
_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/4MNGTBKIXNMMVAIFOLR2W62SLK637OY5/
Code of Conduct: http://python.org/psf/codeofconduct/