try: ...
except group (KeyError, ZeroDivisionError) as error: ... With the precedence you suggest, now group(...) becomes a function call. On 06/10/2021 15:36, Łukasz Langa wrote: >> On 6 Oct 2021, at 16:01, Petr Viktorin <encu...@gmail.com> wrote: >> >> What about this: >> >> group = (KeyboardInterrupt, MemoryError) >> other_group = (KeyError, IndexError) >> >> try: >> ... >> except group + other_group as error: >> ... > Haha, let's see if we can write a Mersienne twister all inside an except > statement 👨🏻🔬 > > Joking aside, since we allow any expression after 'except' 'group' then this > is indeed ambiguous. In theory! In practice, however, PEG is satisfied with > the first rule that matches entirely, so this is a matter of choosing correct > precedence. In this case, it seems it would make sense for "old-style" except > to come first because your (convoluted! 🤠) example is potentially useful, > whereas "except +TimeoutError:" is pure nonsense. > > I will prototype a PR for this just so we can play with it. > > - Ł _______________________________________________ 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/LW4RJO5DTBO7CEYBTT2E7UTHCL6SCXK7/ Code of Conduct: http://python.org/psf/codeofconduct/