This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Tuple unpacking with * causes SyntaxError in with ... as ...
Type: behavior Stage: resolved
Components: Versions: Python 3.9
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, kj, trey
Priority: high Keywords:

Created on 2020-11-13 20:00 by trey, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg380932 - (view) Author: Trey Hunner (trey) * Date: 2020-11-13 20:00
The below code worked on Python 3.5, 3.6, 3.7, and 3.8, but it now crashes on Python 3.9.


from contextlib import contextmanager


@contextmanager
def open_files(names):
    yield names  # This would actually return file objects


with open_files(['file1.txt', 'file2.txt']) as (first, *rest):
    print(first, rest)


The error shown is:

    with open_files(['file1.txt', 'file2.txt']) as (first, *rest):
                                                                 ^
SyntaxError: invalid syntax
msg380961 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2020-11-14 08:31
This is a duplicate of issue bpo-41979, which was already fixed in this merged PR https://github.com/python/cpython/pull/22611 and backported to 3.9.

The example code does not error on the latest 3.10. I'm guessing that the bugfix will come in 3.9.1 since the fix wasn't able to make it into 3.9.0.
msg380974 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2020-11-14 12:00
Already fixed with GH-22612
History
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86520
2020-11-14 12:00:38BTaskayasetstatus: open -> closed

nosy: + BTaskaya
messages: + msg380974

resolution: duplicate
stage: resolved
2020-11-14 08:31:42kjsetnosy: + kj
messages: + msg380961
2020-11-13 20:02:56rhettingersetpriority: normal -> high
2020-11-13 20:00:30treycreate