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 #56991Description
| 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']
ActivityJulian commented 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. merwok commented on Aug 20, 2011 I agree it’s unfortunate that we have to use backslashes to have multi-line with statements. birkenfeld commented on Aug 20, 2011
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*. bitdancer commented on Aug 21, 2011 Following on to Georg's comment about expressions, as a workaround, note
that:
with (
open('abc')) as foo:
works. ncoghlan commented on Aug 22, 2011 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. Julian commented 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? atsuoishimoto commented on Jan 24, 2013 In Python 3.3, we have contextlib.ExitStack() for multiple contexts.
So, perhaps we can close this issue? ezio-melotti commented on Jan 24, 2013 If this can't be fixed I think it should be at least documented in the FAQs. serhiy-storchaka commented on Jan 24, 2013 stevendaprano commented on Feb 16, 2015 warsaw commented on Feb 17, 2015 Let's just Won't Fix this. Use a contextlib.ExitStack. merwok commented on Jan 16, 2022 PEP-8 used with statements as an example of use of backslashes, I am proposing this change: python/peps#2244 gvanrossum commented on Jan 16, 2022 [Meta: Why did adding a comment add all those people (back?) to the nosy list?] merwok commented on Jan 16, 2022 [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]
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|