Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9dec0357
Commit
9dec0357
authored
Jun 30, 2015
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #24528: Improve error message for awaits in comprehensions
parent
4a01cab8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletion
+14
-1
Lib/test/test_coroutines.py
Lib/test/test_coroutines.py
+10
-0
Python/compile.c
Python/compile.c
+4
-1
No files found.
Lib/test/test_coroutines.py
View file @
9dec0357
...
...
@@ -106,6 +106,16 @@ class AsyncBadSyntaxTest(unittest.TestCase):
with
self
.
assertRaisesRegex
(
SyntaxError
,
'invalid syntax'
):
import
test.badsyntax_async9
def
test_badsyntax_10
(
self
):
ns
=
{}
for
comp
in
{
'(await a for a in b)'
,
'[await a for a in b]'
,
'{await a for a in b}'
,
'{await a: c for a in b}'
}:
with
self
.
assertRaisesRegex
(
SyntaxError
,
'await.*in comprehen'
):
exec
(
'async def f():
\
n
\
t
{}'
.
format
(
comp
),
ns
,
ns
)
class
TokenizerRegrTest
(
unittest
.
TestCase
):
...
...
Python/compile.c
View file @
9dec0357
...
...
@@ -3856,7 +3856,10 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
if
(
c
->
u
->
u_ste
->
ste_type
!=
FunctionBlock
)
return
compiler_error
(
c
,
"'await' outside function"
);
/* this check won't be triggered while we have AWAIT token */
if
(
c
->
u
->
u_scope_type
==
COMPILER_SCOPE_COMPREHENSION
)
return
compiler_error
(
c
,
"'await' expressions in comprehensions are not supported"
);
if
(
c
->
u
->
u_scope_type
!=
COMPILER_SCOPE_ASYNC_FUNCTION
)
return
compiler_error
(
c
,
"'await' outside async function"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment