Skip to content

with statement star target #135617

Open
Open
@wwotex

Description

@wwotex

Documentation

https://docs.python.org/3/reference/simple_stmts.html#grammar-token-python-grammar-target

According to the docs, the grammar for the with statement allows:

with_stmt                          ::= "with" with_stmt_contents
with_stmt_contents           ::= with_item
with_item                          ::= expression "as" target
target                                ::= identifier  | "*" target

from my understanding that would allow a python syntax like this:

class Test:
    def __enter__(self):
        return (1, 2)

    def __exit__(self, exc_type, exc_value, traceback):
        pass


with Test() as *mambo:
    print(mambo, type(mambo))

But for me with python version 3.12.8

I get a syntax error:

  File "/home/gringo/accessia/main/controller_start/test.py", line 9
    with Test() as *mambo:
                   ^^^^^^
SyntaxError: starred assignment target must be in a list or tuple

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions