bpo-33672: Fix Task.__repr__ crash with Cython's bogus coroutines (GH-7161)

This commit is contained in:
Yury Selivanov 2018-05-28 16:27:34 -04:00 committed by GitHub
parent 8267ea2e84
commit 989b9e0e6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 39 deletions

View file

@ -1,6 +1,7 @@
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)