On 7/16/2020 10:00 AM, Rhodri James wrote:
On 16/07/2020 17:37, Steve Holden wrote:
While I understand the point of view that says that match ... :
should encapsulate a sequence of indented suites, it seems to me that
match/case/case/.../else has a natural affinity with
try/except/except/.../finally/else, and nobody seems to think that the
excepts should be indented. Or the finally. And naturally the match/else
case are at the same indentation level, just as for/else, while/else and
try/finally. So why, exactly, should case be indented?
My take on the difference would be that "try" tries out a suite, while
"match" matches an expression. If we did:
match:
<expression>
case <pattern>:
<suite>
then having an indented section which must be a single expression
would be unique in Python syntax. I could easily see people being
confused when the slew of statements they would inevitably decide they
must be able to put there, and soon we'd have cats and dogs living
together and the downfall of civilisation as we know it.
Alternatively:
match <expression>:
case <pattern>:
<suite>
would be the one place in Python where you end a line with a colon and
*don't* indent the following line. Writers of simple formatters and
the like (such as Python-mode in Emacs) would curse your name, etc, etc.
My apologies for being a Bear of Very Little Brain.
Nah, don't apologise. This is one of those things that everyone has
opinions on, because there doesn't seem to be an obvious Right Answer.
Speaking of things unique in Python syntax, isn't double-indention of a
single control flow structure introduced by match also unique?
_______________________________________________
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/E26GHBGQCGROPUJZBRY66GVKDWOQT4ZX/
Code of Conduct: http://python.org/psf/codeofconduct/