On Wed, Jun 24, 2020 at 5:30 AM Rob Cliffe via Python-Dev <python-dev@python.org> wrote: > > The PEP is great, but this strikes me as horribly confusing, given that > 401|403|404 is already legal syntax. > IIUC any legal expression can come between `case` and `:`, but expressions > that contain `|` at their outermost level are interpreted differently than > from in other contexts. > Presumably adding parentheses: > case (401|403|404): > would make it equivalent to > case 407: > > Is a separator (other than whitespace) actually needed? Can the parser cope > with > case 401 403 404: > > Failing that IMO preferable, albeit not ideal, possibilities would be > 1) Use colon as the separator. > 2) Use comma as the separator - this is already legal syntax too, but IMO > it reads more naturally. > (And IIRC there are already contexts where brackets are necessary to > indicate a tuple.) > Perhaps someone can think of something better. > > I also (with others) prefer `else:` or perhaps `case else:` to using the`_` > variable. > The latter is obscure, and woudn't sit well with code that already uses that > variable for its own purposes. >
It's not really arbitrary expressions, though. It's more like an assignment target list, but with some handling of constants. case (x, y): is very similar to (x, y) = ... There is the definite risk of confusion with 'if' statements, because you can say "case 401|403|404:" but you can't say "if x == 401|403|404:", and people already try to do that (usually with the 'or' keyword). I think the risk is worth it, given the expressiveness gained, but I can see the line of argument that it's going to cause confusion. ChrisA _______________________________________________ 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/GEMFLQCNZG3WPZYTBNC54S4A3XLIUMPR/ Code of Conduct: http://python.org/psf/codeofconduct/