- Notifications
You must be signed in to change notification settings - Fork1.3k
Description
Feature
In Python 3.11, theexcept*
was added for working withExceptionGroup
s. The availability ofExceptionGroup
itself will depend on#4247, but in the meantime, the following snippet is valid CPython 3.11 that currently throws aSyntaxError
in RustPython:
try:print("yay")except*Exceptionase:print("oh no")
I discovered this while digging into some code thatruff cannot handle, which on the surface looks like a slightly different issue. The following snippet is valid CPython 3.11 but also throws aSyntaxError
in RustPython:
my_dict= {}my_dict[*"ab"]=1
The expected behaviour is that the string should be unpacked and the value of the dict with key('a','b')
set to 1. In case that feels a little contrived, here's what I was doing at the time:
importtypingvalues= ["dog","cat"]Pets=typing.Literal[*values]
Python Documentation
The first incompatibility issue is clearly documentedhere, and called out underNew syntax features inWhat’s New In Python 3.11.
However the second incompatibility is not documented in the changelog, and I did confirm that this was new in CPython 3.11, as the snippet throws a syntax error in 3.10.
I wonder if this was a (nice?) side-effect of the changes that were introduced to makeexcept*
work. There is aseemingly related precedent for this, where using*
to unpack without parentheses infor
statements was enabled via the PEG parser in CPython 3.9, but was not noticed then and only documented in 3.11.