Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

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

Open
Labels
A-vmArea: virtual machine
@ned2

Description

@ned2

Feature

In Python 3.11, theexcept* was added for working withExceptionGroups. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-vmArea: virtual machine

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp