Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Two CPython 3.11 syntax changes involving * operator are unsupported #4479

Copy link
Copy link
Open
@ned2

Description

@ned2
Issue body actions

Feature

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:

try:
    print("yay")
except* Exception as e:
    print("oh no")

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:

import typing
values = ["dog", "cat"]
Pets = typing.Literal[*values]

Python Documentation

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-vmArea: virtual machineArea: virtual machine

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.