GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Multiple context expressions do not support parentheses for continuation across lines · Issue #56991 · python/cpython

Multiple context expressions do not support parentheses for continuation across lines #56991

New issue
Copy link
New issue
Copy link
Closed
Closed
Multiple context expressions do not support parentheses for continuation across lines#56991
Copy link
Assignees
pablogsal
Labels
3.10 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

Description

Julian
mannequin
opened on Aug 19, 2011
Issue body actions
BPO 12782
Nosy @gvanrossum, @warsaw, @birkenfeld, @atsuoishimoto, @ncoghlan, @benjaminp, @ezio-melotti, @merwok, @stevendaprano, @bitdancer, @ambv, @Julian, @serhiy-storchaka, @asottile, @pablogsal, @thautwarm, @isidentical, @websurfer5, @jack1142

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/pablogsal'
closed_at = <Date 2020-06-25.19:11:20.497>
created_at = <Date 2011-08-19.02:10:17.157>
labels = ['interpreter-core', 'type-feature', '3.10']
title = 'Multiple context expressions do not support parentheses for continuation across lines'
updated_at = <Date 2022-01-16.22:14:02.746>
user = 'https://github.com/Julian'

bugs.python.org fields:

activity = <Date 2022-01-16.22:14:02.746>
actor = 'eric.araujo'
assignee = 'pablogsal'
closed = True
closed_date = <Date 2020-06-25.19:11:20.497>
closer = 'pablogsal'
components = ['Interpreter Core']
creation = <Date 2011-08-19.02:10:17.157>
creator = 'Julian'
dependencies = []
files = []
hgrepos = []
issue_num = 12782
keywords = ['patch']
message_count = 29.0
messages = ['142411', '142549', '142550', '142631', '142658', '142750', '180512', '180514', '180515', '236083', '236121', '293660', '326637', '326639', '326645', '326648', '326727', '327875', '346137', '346157', '347025', '363755', '372383', '372384', '372385', '372388', '410726', '410728', '410729']
nosy_count = 21.0
nosy_names = ['gvanrossum', 'barry', 'georg.brandl', 'ishimoto', 'ncoghlan', 'benjamin.peterson', 'ezio.melotti', 'eric.araujo', 'steven.daprano', 'r.david.murray', 'lukasz.langa', 'Julian', 'serhiy.storchaka', 'ulope', 'Anthony Sottile', 'pablogsal', 'thautwarm', 'BTaskaya', 'Terry Davis', 'Jeffrey.Kintscher', 'jack1142']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue12782'
versions = ['Python 3.10']

Activity

Next
  1. Julian commented on Aug 19, 2011

    @Julian
    Julianmannequin
    on Aug 19, 2011
    MannequinAuthor
    More actions

    Using multiple with statements across multiple lines does not support using parens to break them up:

    with (open("a_really_long_foo") as foo,
          open("a_really_long_bar") as bar):
        pass
    Traceback (most recent call last):
      File "<input>", line 1, in <module>
      File "demo.py", line 19
        with (open("a_really_long_foo") as foo,
                                        ^
    SyntaxError: invalid syntax

    Also, without convoluting things, import also does not support doing so, and is the only other example I can think of of a compound statement that forces you to either be redundant or bite your teeth and use \, despite the fact that PEP-328 gave us parens for from imports.

    (I did not find a discussion as to why import didn't grow it as well, so please correct me as I'm sure it must have been discussed before).

    It's understandably a lot rarer to need multiple lines when importing, but it'd be nice if all compound statements uniformly allowed the same continuation syntax.

  2. Julian
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Aug 19, 2011
  3. pitrou
    added
    type-featureA feature request or enhancementA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Aug 19, 2011
  4. merwok commented on Aug 20, 2011

    @merwok
    merwok
    on Aug 20, 2011
    Member
    More actions

    I agree it’s unfortunate that we have to use backslashes to have multi-line with statements.

  5. birkenfeld commented on Aug 20, 2011

    @birkenfeld
    birkenfeld
    on Aug 20, 2011
    Member
    More actions

    is the only other example I can think of

    One similar example would be "raise" in Python 2.

    all compound statements uniformly allowed the same continuation syntax.

    This is not true: only "import-as" allows this syntax. All other uses of parentheses for continuation are continuations of *expressions*.

  6. bitdancer commented on Aug 21, 2011

    @bitdancer
    bitdancer
    on Aug 21, 2011
    Member
    More actions

    Following on to Georg's comment about expressions, as a workaround, note
    that:

      with (
         open('abc')) as foo:

    works.

    Reacted by Mark Hudson
  7. ncoghlan commented on Aug 22, 2011

    @ncoghlan
    ncoghlan
    on Aug 22, 2011
    Contributor
    More actions

    As Georg noted, only individual expressions get parentheses based continuations automatically. For statement level use of comma separation, it's decided on a case-by-cases basis as to whether we think it is a legitimate usage based on our style guidelines.

    That's why 'from location import (name1, name2)' is allowed, but 'import (name1, name2)' is not: we explicitly advise against importing too many modules in a single import statement, but importing multiple names from a single location is often a useful thing to do.

    However, while the multiple context expression use case is reasonable, there may be a grammar ambiguity problem in this case, since (unlike from-import) with statements allow arbitrary subexpressions.

    Reacted by Rowinder
  8. Julian commented on Aug 22, 2011

    @Julian
    Julianmannequin
    on Aug 22, 2011
    MannequinAuthor
    More actions

    we explicitly advise against importing too many modules in a single import statement, but importing multiple names from a single location is often a useful thing to do.

    Cool. I imagined this had to do with it.

    there may be a grammar ambiguity problem in this case, since (unlike from-import) with statements allow arbitrary subexpressions.

    Sorry, can you possibly clarify where the ambiguity might come in?

  9. atsuoishimoto commented on Jan 24, 2013

    @atsuoishimoto
    atsuoishimotomannequin
    on Jan 24, 2013
    Mannequin
    More actions

    In Python 3.3, we have contextlib.ExitStack() for multiple contexts.
    So, perhaps we can close this issue?

  10. ezio-melotti commented on Jan 24, 2013

    @ezio-melotti
    ezio-melotti
    on Jan 24, 2013
    Member
    More actions

    If this can't be fixed I think it should be at least documented in the FAQs.

  11. serhiy-storchaka commented on Jan 24, 2013

    @serhiy-storchaka
    serhiy-storchaka
    on Jan 24, 2013
    Member
    More actions

    There is a discussion about this on Python-Ideas:

    http://comments.gmane.org/gmane.comp.python.ideas/17597
    http://mail.python.org/pipermail/python-ideas/2012-October/017610.html

  12. stevendaprano commented on Feb 16, 2015

    @stevendaprano
    stevendaprano
    on Feb 16, 2015
    Member
    More actions

    This has come up on Python-Ideas again:

    http://permalink.gmane.org/gmane.comp.python.ideas/32002

    https://mail.python.org/pipermail/python-ideas/2015-February/032000.html

  13. warsaw commented on Feb 17, 2015

    @warsaw
    warsaw
    on Feb 17, 2015
    Member
    More actions

    Let's just Won't Fix this. Use a contextlib.ExitStack.

  14. 21 remaining items

  15. ahmedsayeed1982
    added
    topic-IDLE
    3.8 (EOL)end of lifeend of life
    and removed
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Nov 4, 2021
  16. eryksun
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    and removed
    topic-IDLE
    on Nov 4, 2021
  17. merwok commented on Jan 16, 2022

    @merwok
    merwok
    on Jan 16, 2022
    Member
    More actions

    PEP-8 used with statements as an example of use of backslashes, I am proposing this change: python/peps#2244

  18. merwok
    added
    3.10 (EOL)end of lifeend of life
    and removed
    3.8 (EOL)end of lifeend of life
    on Jan 16, 2022
  19. gvanrossum commented on Jan 16, 2022

    @gvanrossum
    gvanrossum
    on Jan 16, 2022
    Member
    More actions

    [Meta: Why did adding a comment add all those people (back?) to the nosy list?]

  20. merwok commented on Jan 16, 2022

    @merwok
    merwok
    on Jan 16, 2022
    Member
    More actions

    [There are two separate events in the ticket log: I added my comment, then noticed I was the only nosy so I found all the prople recently removed by error and re-added them]

  21. ezio-melotti
    transferred this issue fromon Apr 10, 2022
  22. keszybz
    added 2 commits that reference this issue on Oct 29, 2023

    Reformat with statements to not use backslashes

    80ebd7e

    Reformat with statements to not use backslashes

    34185aa
  23. ntBre
    added a commit that references this issue on Mar 17, 2025

    [syntax-errors] Parenthesized context managers before Python 3.9 (#16523

    75a562d
  24. KotlinIsland
    added a commit that references this issue on May 1, 2026

    [syntax-errors] Parenthesized context managers before Python 3.9 (#16…

    ecb3f9f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @pablogsal
    pablogsal

Labels

3.10 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.