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
a68f2f05
Unverified
Kaydet (Commit)
a68f2f05
authored
Nis 02, 2018
tarafından
Serhiy Storchaka
Kaydeden (comit)
GitHub
Nis 02, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-29922: Improve error messages in 'async with' (GH-6352)
when __aenter__() or __aexit__() return non-awaitable object.
üst
55966f3a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
4 deletions
+36
-4
test_coroutines.py
Lib/test/test_coroutines.py
+9
-4
2018-04-03-00-30-25.bpo-29922.CdLuMl.rst
...ore and Builtins/2018-04-03-00-30-25.bpo-29922.CdLuMl.rst
+2
-0
ceval.c
Python/ceval.c
+25
-0
No files found.
Lib/test/test_coroutines.py
Dosyayı görüntüle @
a68f2f05
...
@@ -1255,7 +1255,9 @@ class CoroutineTest(unittest.TestCase):
...
@@ -1255,7 +1255,9 @@ class CoroutineTest(unittest.TestCase):
pass
pass
with
self
.
assertRaisesRegex
(
with
self
.
assertRaisesRegex
(
TypeError
,
"object int can't be used in 'await' expression"
):
TypeError
,
"'async with' received an object from __aenter__ "
"that does not implement __await__: int"
):
# it's important that __aexit__ wasn't called
# it's important that __aexit__ wasn't called
run_async
(
foo
())
run_async
(
foo
())
...
@@ -1275,7 +1277,9 @@ class CoroutineTest(unittest.TestCase):
...
@@ -1275,7 +1277,9 @@ class CoroutineTest(unittest.TestCase):
run_async
(
foo
())
run_async
(
foo
())
except
TypeError
as
exc
:
except
TypeError
as
exc
:
self
.
assertRegex
(
self
.
assertRegex
(
exc
.
args
[
0
],
"object int can't be used in 'await' expression"
)
exc
.
args
[
0
],
"'async with' received an object from __aexit__ "
"that does not implement __await__: int"
)
self
.
assertTrue
(
exc
.
__context__
is
not
None
)
self
.
assertTrue
(
exc
.
__context__
is
not
None
)
self
.
assertTrue
(
isinstance
(
exc
.
__context__
,
ZeroDivisionError
))
self
.
assertTrue
(
isinstance
(
exc
.
__context__
,
ZeroDivisionError
))
else
:
else
:
...
@@ -1299,8 +1303,9 @@ class CoroutineTest(unittest.TestCase):
...
@@ -1299,8 +1303,9 @@ class CoroutineTest(unittest.TestCase):
with
self
.
assertRaisesRegex
(
with
self
.
assertRaisesRegex
(
TypeError
,
"object int can't be used in 'await' expression"
):
TypeError
,
"'async with' received an object from __aexit__ "
"that does not implement __await__: int"
):
run_async
(
foo
())
run_async
(
foo
())
self
.
assertEqual
(
CNT
,
1
)
self
.
assertEqual
(
CNT
,
1
)
...
...
Misc/NEWS.d/next/Core and Builtins/2018-04-03-00-30-25.bpo-29922.CdLuMl.rst
0 → 100644
Dosyayı görüntüle @
a68f2f05
Improved error messages in 'async with' when ``__aenter__()`` or
``__aexit__()`` return non-awaitable object.
Python/ceval.c
Dosyayı görüntüle @
a68f2f05
...
@@ -69,6 +69,7 @@ static PyObject * unicode_concatenate(PyObject *, PyObject *,
...
@@ -69,6 +69,7 @@ static PyObject * unicode_concatenate(PyObject *, PyObject *,
static
PyObject
*
special_lookup
(
PyObject
*
,
_Py_Identifier
*
);
static
PyObject
*
special_lookup
(
PyObject
*
,
_Py_Identifier
*
);
static
int
check_args_iterable
(
PyObject
*
func
,
PyObject
*
vararg
);
static
int
check_args_iterable
(
PyObject
*
func
,
PyObject
*
vararg
);
static
void
format_kwargs_mapping_error
(
PyObject
*
func
,
PyObject
*
kwargs
);
static
void
format_kwargs_mapping_error
(
PyObject
*
func
,
PyObject
*
kwargs
);
static
void
format_awaitable_error
(
PyTypeObject
*
,
int
);
#define NAME_ERROR_MSG \
#define NAME_ERROR_MSG \
"name '%.200s' is not defined"
"name '%.200s' is not defined"
...
@@ -1736,6 +1737,11 @@ main_loop:
...
@@ -1736,6 +1737,11 @@ main_loop:
PyObject
*
iterable
=
TOP
();
PyObject
*
iterable
=
TOP
();
PyObject
*
iter
=
_PyCoro_GetAwaitableIter
(
iterable
);
PyObject
*
iter
=
_PyCoro_GetAwaitableIter
(
iterable
);
if
(
iter
==
NULL
)
{
format_awaitable_error
(
Py_TYPE
(
iterable
),
_Py_OPCODE
(
next_instr
[
-
2
]));
}
Py_DECREF
(
iterable
);
Py_DECREF
(
iterable
);
if
(
iter
!=
NULL
&&
PyCoro_CheckExact
(
iter
))
{
if
(
iter
!=
NULL
&&
PyCoro_CheckExact
(
iter
))
{
...
@@ -4985,6 +4991,25 @@ format_exc_unbound(PyCodeObject *co, int oparg)
...
@@ -4985,6 +4991,25 @@ format_exc_unbound(PyCodeObject *co, int oparg)
}
}
}
}
static
void
format_awaitable_error
(
PyTypeObject
*
type
,
int
prevopcode
)
{
if
(
type
->
tp_as_async
==
NULL
||
type
->
tp_as_async
->
am_await
==
NULL
)
{
if
(
prevopcode
==
BEFORE_ASYNC_WITH
)
{
PyErr_Format
(
PyExc_TypeError
,
"'async with' received an object from __aenter__ "
"that does not implement __await__: %.100s"
,
type
->
tp_name
);
}
else
if
(
prevopcode
==
WITH_CLEANUP_START
)
{
PyErr_Format
(
PyExc_TypeError
,
"'async with' received an object from __aexit__ "
"that does not implement __await__: %.100s"
,
type
->
tp_name
);
}
}
}
static
PyObject
*
static
PyObject
*
unicode_concatenate
(
PyObject
*
v
,
PyObject
*
w
,
unicode_concatenate
(
PyObject
*
v
,
PyObject
*
w
,
PyFrameObject
*
f
,
const
_Py_CODEUNIT
*
next_instr
)
PyFrameObject
*
f
,
const
_Py_CODEUNIT
*
next_instr
)
...
...
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