Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
b8ab9d3f
Kaydet (Commit)
b8ab9d3f
authored
Eki 06, 2017
tarafından
Yury Selivanov
Kaydeden (comit)
GitHub
Eki 06, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-31708: Allow async generator expressions in synchronous functions (#3905)
üst
faa135ac
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
9 deletions
+52
-9
expressions.rst
Doc/reference/expressions.rst
+10
-8
test_asyncgen.py
Lib/test/test_asyncgen.py
+32
-0
test_coroutines.py
Lib/test/test_coroutines.py
+8
-0
2017-10-06-02-10-48.bpo-31708.66CCVU.rst
...ore and Builtins/2017-10-06-02-10-48.bpo-31708.66CCVU.rst
+1
-0
compile.c
Python/compile.c
+1
-1
No files found.
Doc/reference/expressions.rst
Dosyayı görüntüle @
b8ab9d3f
...
...
@@ -326,14 +326,16 @@ range(10) for y in bar(x))``.
The parentheses can be omitted on calls with only one argument. See section
:ref:`calls` for details.
Since Python 3.6, if the generator appears in an :keyword:`async def` function,
then :keyword:`async for` clauses and :keyword:`await` expressions are permitted
as with an asynchronous comprehension. If a generator expression
contains either :keyword:`async for` clauses or :keyword:`await` expressions
it is called an :dfn:`asynchronous generator expression`.
An asynchronous generator expression yields a new asynchronous
generator object, which is an asynchronous iterator
(see :ref:`async-iterators`).
If a generator expression contains either :keyword:`async for`
clauses or :keyword:`await` expressions it is called an
:dfn:`asynchronous generator expression`. An asynchronous generator
expression returns a new asynchronous generator object,
which is an asynchronous iterator (see :ref:`async-iterators`).
.. versionchanged:: 3.7
Prior to Python 3.7, asynchronous generator expressions could
only appear in :keyword:`async def` coroutines. Starting
with 3.7, any function can use asynchronous generator expressions.
.. _yieldexpr:
...
...
Lib/test/test_asyncgen.py
Dosyayı görüntüle @
b8ab9d3f
...
...
@@ -1037,5 +1037,37 @@ class AsyncGenAsyncioTest(unittest.TestCase):
t
.
cancel
()
self
.
loop
.
run_until_complete
(
asyncio
.
sleep
(
0.1
,
loop
=
self
.
loop
))
def
test_async_gen_expression_01
(
self
):
async
def
arange
(
n
):
for
i
in
range
(
n
):
await
asyncio
.
sleep
(
0.01
,
loop
=
self
.
loop
)
yield
i
def
make_arange
(
n
):
# This syntax is legal starting with Python 3.7
return
(
i
*
2
async
for
i
in
arange
(
n
))
async
def
run
():
return
[
i
async
for
i
in
make_arange
(
10
)]
res
=
self
.
loop
.
run_until_complete
(
run
())
self
.
assertEqual
(
res
,
[
i
*
2
for
i
in
range
(
10
)])
def
test_async_gen_expression_02
(
self
):
async
def
wrap
(
n
):
await
asyncio
.
sleep
(
0.01
,
loop
=
self
.
loop
)
return
n
def
make_arange
(
n
):
# This syntax is legal starting with Python 3.7
return
(
i
*
2
for
i
in
range
(
n
)
if
await
wrap
(
i
))
async
def
run
():
return
[
i
async
for
i
in
make_arange
(
10
)]
res
=
self
.
loop
.
run_until_complete
(
run
())
self
.
assertEqual
(
res
,
[
i
*
2
for
i
in
range
(
1
,
10
)])
if
__name__
==
"__main__"
:
unittest
.
main
()
Lib/test/test_coroutines.py
Dosyayı görüntüle @
b8ab9d3f
...
...
@@ -149,6 +149,14 @@ class AsyncBadSyntaxTest(unittest.TestCase):
[i async for i in els]
"""
,
"""def bar():
{i: i async for i in els}
"""
,
"""def bar():
{i async for i in els}
"""
,
"""def bar():
[await i for i in els]
"""
,
...
...
Misc/NEWS.d/next/Core and Builtins/2017-10-06-02-10-48.bpo-31708.66CCVU.rst
0 → 100644
Dosyayı görüntüle @
b8ab9d3f
Allow use of asynchronous generator expressions in synchronous functions.
Python/compile.c
Dosyayı görüntüle @
b8ab9d3f
...
...
@@ -3974,7 +3974,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
is_async_generator
=
c
->
u
->
u_ste
->
ste_coroutine
;
if
(
is_async_generator
&&
!
is_async_function
)
{
if
(
is_async_generator
&&
!
is_async_function
&&
type
!=
COMP_GENEXP
)
{
if
(
e
->
lineno
>
c
->
u
->
u_lineno
)
{
c
->
u
->
u_lineno
=
e
->
lineno
;
c
->
u
->
u_lineno_set
=
0
;
...
...
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