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
989b9e0e
Unverified
Kaydet (Commit)
989b9e0e
authored
May 28, 2018
tarafından
Yury Selivanov
Kaydeden (comit)
GitHub
May 28, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-33672: Fix Task.__repr__ crash with Cython's bogus coroutines (GH-7161)
üst
8267ea2e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
40 deletions
+61
-40
coroutines.py
Lib/asyncio/coroutines.py
+45
-36
format_helpers.py
Lib/asyncio/format_helpers.py
+5
-4
test_events.py
Lib/test/test_asyncio/test_events.py
+10
-0
2018-05-28-12-29-54.bpo-33672.GM_Xm_.rst
...S.d/next/Library/2018-05-28-12-29-54.bpo-33672.GM_Xm_.rst
+1
-0
No files found.
Lib/asyncio/coroutines.py
Dosyayı görüntüle @
989b9e0e
...
...
@@ -189,56 +189,63 @@ def iscoroutine(obj):
def
_format_coroutine
(
coro
):
assert
iscoroutine
(
coro
)
if
not
hasattr
(
coro
,
'cr_code'
)
and
not
hasattr
(
coro
,
'gi_code'
):
# Most likely a built-in type or a Cython coroutine.
# Built-in types might not have __qualname__ or __name__.
coro_name
=
getattr
(
coro
,
'__qualname__'
,
getattr
(
coro
,
'__name__'
,
type
(
coro
)
.
__name__
))
coro_name
=
f
'{coro_name}()'
is_corowrapper
=
isinstance
(
coro
,
CoroWrapper
)
def
get_name
(
coro
):
# Coroutines compiled with Cython sometimes don't have
# proper __qualname__ or __name__. While that is a bug
# in Cython, asyncio shouldn't crash with an AttributeError
# in its __repr__ functions.
if
is_corowrapper
:
return
format_helpers
.
_format_callback
(
coro
.
func
,
(),
{})
if
hasattr
(
coro
,
'__qualname__'
)
and
coro
.
__qualname__
:
coro_name
=
coro
.
__qualname__
elif
hasattr
(
coro
,
'__name__'
)
and
coro
.
__name__
:
coro_name
=
coro
.
__name__
else
:
# Stop masking Cython bugs, expose them in a friendly way.
coro_name
=
f
'<{type(coro).__name__} without __name__>'
return
f
'{coro_name}()'
running
=
False
def
is_running
(
coro
):
try
:
r
unning
=
coro
.
cr_running
r
eturn
coro
.
cr_running
except
AttributeError
:
try
:
r
unning
=
coro
.
gi_running
r
eturn
coro
.
gi_running
except
AttributeError
:
pass
return
False
if
running
:
coro_code
=
None
if
hasattr
(
coro
,
'cr_code'
)
and
coro
.
cr_code
:
coro_code
=
coro
.
cr_code
elif
hasattr
(
coro
,
'gi_code'
)
and
coro
.
gi_code
:
coro_code
=
coro
.
gi_code
coro_name
=
get_name
(
coro
)
if
not
coro_code
:
# Built-in types might not have __qualname__ or __name__.
if
is_running
(
coro
):
return
f
'{coro_name} running'
else
:
return
coro_name
coro_name
=
None
if
isinstance
(
coro
,
CoroWrapper
):
func
=
coro
.
func
coro_name
=
coro
.
__qualname__
if
coro_name
is
not
None
:
coro_name
=
f
'{coro_name}()'
else
:
func
=
coro
if
coro_name
is
None
:
coro_name
=
format_helpers
.
_format_callback
(
func
,
(),
{})
try
:
coro_code
=
coro
.
gi_code
except
AttributeError
:
coro_code
=
coro
.
cr_code
try
:
coro_frame
=
None
if
hasattr
(
coro
,
'gi_frame'
)
and
coro
.
gi_frame
:
coro_frame
=
coro
.
gi_frame
e
xcept
AttributeError
:
e
lif
hasattr
(
coro
,
'cr_frame'
)
and
coro
.
cr_frame
:
coro_frame
=
coro
.
cr_frame
filename
=
coro_code
.
co_filename
# If Cython's coroutine has a fake code object without proper
# co_filename -- expose that.
filename
=
coro_code
.
co_filename
or
'<empty co_filename>'
lineno
=
0
if
(
is
instance
(
coro
,
CoroWrapper
)
and
not
inspect
.
isgeneratorfunction
(
coro
.
func
)
and
coro
.
func
is
not
None
):
if
(
is
_corowrapper
and
coro
.
func
is
not
None
and
not
inspect
.
isgeneratorfunction
(
coro
.
func
)
):
source
=
format_helpers
.
_get_function_source
(
coro
.
func
)
if
source
is
not
None
:
filename
,
lineno
=
source
...
...
@@ -246,9 +253,11 @@ def _format_coroutine(coro):
coro_repr
=
f
'{coro_name} done, defined at {filename}:{lineno}'
else
:
coro_repr
=
f
'{coro_name} running, defined at {filename}:{lineno}'
elif
coro_frame
is
not
None
:
lineno
=
coro_frame
.
f_lineno
coro_repr
=
f
'{coro_name} running at {filename}:{lineno}'
else
:
lineno
=
coro_code
.
co_firstlineno
coro_repr
=
f
'{coro_name} done, defined at {filename}:{lineno}'
...
...
Lib/asyncio/format_helpers.py
Dosyayı görüntüle @
989b9e0e
import
functools
import
inspect
import
reprlib
import
sys
import
traceback
from
.
import
constants
...
...
@@ -45,10 +46,10 @@ def _format_callback(func, args, kwargs, suffix=''):
suffix
=
_format_args_and_kwargs
(
args
,
kwargs
)
+
suffix
return
_format_callback
(
func
.
func
,
func
.
args
,
func
.
keywords
,
suffix
)
if
hasattr
(
func
,
'__qualname__'
):
func_repr
=
getattr
(
func
,
'__qualname__'
)
elif
hasattr
(
func
,
'__name__'
):
func_repr
=
getattr
(
func
,
'__name__'
)
if
hasattr
(
func
,
'__qualname__'
)
and
func
.
__qualname__
:
func_repr
=
func
.
__qualname__
elif
hasattr
(
func
,
'__name__'
)
and
func
.
__name__
:
func_repr
=
func
.
__name__
else
:
func_repr
=
repr
(
func
)
...
...
Lib/test/test_asyncio/test_events.py
Dosyayı görüntüle @
989b9e0e
...
...
@@ -2784,11 +2784,21 @@ class HandleTests(test_utils.TestCase):
coro
.
cr_running
=
True
self
.
assertEqual
(
coroutines
.
_format_coroutine
(
coro
),
'BBB() running'
)
coro
.
__name__
=
coro
.
__qualname__
=
None
self
.
assertEqual
(
coroutines
.
_format_coroutine
(
coro
),
'<CoroLike without __name__>() running'
)
coro
=
CoroLike
()
coro
.
__qualname__
=
'CoroLike'
# Some coroutines might not have '__name__', such as
# built-in async_gen.asend().
self
.
assertEqual
(
coroutines
.
_format_coroutine
(
coro
),
'CoroLike()'
)
coro
=
CoroLike
()
coro
.
__qualname__
=
'AAA'
coro
.
cr_code
=
None
self
.
assertEqual
(
coroutines
.
_format_coroutine
(
coro
),
'AAA()'
)
class
TimerTests
(
unittest
.
TestCase
):
...
...
Misc/NEWS.d/next/Library/2018-05-28-12-29-54.bpo-33672.GM_Xm_.rst
0 → 100644
Dosyayı görüntüle @
989b9e0e
Fix Task.__repr__ crash with Cython's bogus coroutines
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