You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Two CPython 3.11 syntax changes involving * operator are unsupported #4479
In Python 3.11, the except* was added for working with ExceptionGroups. The availability of ExceptionGroup itself will depend on #4247, but in the meantime, the following snippet is valid CPython 3.11 that currently throws a SyntaxError in RustPython:
I discovered this while digging into some code that ruff cannot handle, which on the surface looks like a slightly different issue. The following snippet is valid CPython 3.11 but also throws a SyntaxError 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:
The first incompatibility issue is clearly documented here, and called out under New syntax features in What’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 make except* work. There is a seemingly related precedent for this, where using * to unpack without parentheses in for statements was enabled via the PEG parser in CPython 3.9, but was not noticed then and only documented in 3.11.
Unpacking in indexes was introduced with PEP 646 (specifically, see here). I guess it isn't documented in that section because it isn't new syntax per se, more of a change in where * is allowed (it probably should be in the Other Language Changes though, which also mentions another small syntax change).
let's break this up in two issues? they touch on different subjects and the unpacking might be a good issue for someone to tackle. (plus, the title doesn't make it obvious that the parsing part of this is solved but the runtime isn't)
Activity
DimitrisJim commentedon Jan 31, 2023
Unpacking in indexes was introduced with PEP 646 (specifically, see here). I guess it isn't documented in that section because it isn't new syntax per se, more of a change in where
*is allowed (it probably should be in the Other Language Changes though, which also mentions another small syntax change).ned2 commentedon Jan 31, 2023
ahhh nice yes, that's exactly it! turns out that is a hard document to find with Google. I certainly looked for it.
yeah agreed, would have been good to see that in the Other Language Changes section
charliermarsh commentedon Feb 21, 2023
Fixed :)
youknowone commentedon Feb 21, 2023
resolved by @charliermarsh , thanks!
youknowone commentedon Feb 21, 2023
I am sorry, the parser part is done but runtime is not.
charliermarsh commentedon Feb 21, 2023
Ah correct!
fanninpm commentedon Feb 21, 2023
cc @qingshi163 for inclusion in #4423
DimitrisJim commentedon Feb 22, 2023
let's break this up in two issues? they touch on different subjects and the unpacking might be a good issue for someone to tackle. (plus, the title doesn't make it obvious that the parsing part of this is solved but the runtime isn't)