On 06. 10. 21 15:34, Łukasz Langa wrote:
On 6 Oct 2021, at 12:06, Larry Hastings <email@example.com mailto:firstname.lastname@example.org> wrote:
It seems like, for this to work, "group" would have to become a keyword.
No, just like `match` and `case` didn't have to.
This would play havoc with a lot of existing code.
Extraordinary claims require extraordinary evidence, Larry. I maintain this will be entirely backwards compatible.
Even making it a soft keyword, a la "await" in 3.5, would lead to ambiguity:
group = KeyboardInterrupt try: while True: print("thou can only defeat me with Ctrl-C") except group as error: print("lo, thou hast defeated me")
- This is a convoluted example, I bet $100 you won't find such an
`except group` statement in any code predating my e-mail 🤠 Sure, sometimes (very rarely) it's useful to gather exceptions in a variable. But I'm pretty sure `group` won't be the name chosen for it.
- While non-obvious, the example is not ambiguous. There can only be
one parsing rule fitting this:
'except' expression 'as' NAME ':'
Note how this is different from:
'except' 'group' expression 'as' NAME ':'
There could be confusion if except-star, whatever its name is going to be, supported an empty "catch all" variant like `except:`. Thankfully, this is explicitly listed as a no-go in PEP 654. So `except group:` remains unambiguous.
What about this:
group = (KeyboardInterrupt, MemoryError) other_group = (KeyError, IndexError)
try: ... except group + other_group as error: ...