mirror of https://github.com/python/cpython
Merge 3.5 (issue #26654)
This commit is contained in:
commit
62b81c33d1
|
@ -271,7 +271,7 @@ def _format_coroutine(coro):
|
||||||
func = coro
|
func = coro
|
||||||
|
|
||||||
if coro_name is None:
|
if coro_name is None:
|
||||||
coro_name = events._format_callback(func, ())
|
coro_name = events._format_callback(func, (), {})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
coro_code = coro.gi_code
|
coro_code = coro.gi_code
|
||||||
|
|
|
@ -35,23 +35,25 @@ def _get_function_source(func):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _format_args(args):
|
def _format_args_and_kwargs(args, kwargs):
|
||||||
"""Format function arguments.
|
"""Format function arguments and keyword arguments.
|
||||||
|
|
||||||
Special case for a single parameter: ('hello',) is formatted as ('hello').
|
Special case for a single parameter: ('hello',) is formatted as ('hello').
|
||||||
"""
|
"""
|
||||||
# use reprlib to limit the length of the output
|
# use reprlib to limit the length of the output
|
||||||
args_repr = reprlib.repr(args)
|
items = []
|
||||||
if len(args) == 1 and args_repr.endswith(',)'):
|
if args:
|
||||||
args_repr = args_repr[:-2] + ')'
|
items.extend(reprlib.repr(arg) for arg in args)
|
||||||
return args_repr
|
if kwargs:
|
||||||
|
items.extend('{}={}'.format(k, reprlib.repr(v))
|
||||||
|
for k, v in kwargs.items())
|
||||||
|
return '(' + ', '.join(items) + ')'
|
||||||
|
|
||||||
|
|
||||||
def _format_callback(func, args, suffix=''):
|
def _format_callback(func, args, kwargs, suffix=''):
|
||||||
if isinstance(func, functools.partial):
|
if isinstance(func, functools.partial):
|
||||||
if args is not None:
|
suffix = _format_args_and_kwargs(args, kwargs) + suffix
|
||||||
suffix = _format_args(args) + suffix
|
return _format_callback(func.func, func.args, func.keywords, suffix)
|
||||||
return _format_callback(func.func, func.args, suffix)
|
|
||||||
|
|
||||||
if hasattr(func, '__qualname__'):
|
if hasattr(func, '__qualname__'):
|
||||||
func_repr = getattr(func, '__qualname__')
|
func_repr = getattr(func, '__qualname__')
|
||||||
|
@ -60,14 +62,13 @@ def _format_callback(func, args, suffix=''):
|
||||||
else:
|
else:
|
||||||
func_repr = repr(func)
|
func_repr = repr(func)
|
||||||
|
|
||||||
if args is not None:
|
func_repr += _format_args_and_kwargs(args, kwargs)
|
||||||
func_repr += _format_args(args)
|
|
||||||
if suffix:
|
if suffix:
|
||||||
func_repr += suffix
|
func_repr += suffix
|
||||||
return func_repr
|
return func_repr
|
||||||
|
|
||||||
def _format_callback_source(func, args):
|
def _format_callback_source(func, args):
|
||||||
func_repr = _format_callback(func, args)
|
func_repr = _format_callback(func, args, None)
|
||||||
source = _get_function_source(func)
|
source = _get_function_source(func)
|
||||||
if source:
|
if source:
|
||||||
func_repr += ' at %s:%s' % source
|
func_repr += ' at %s:%s' % source
|
||||||
|
|
|
@ -2224,7 +2224,7 @@ else:
|
||||||
return asyncio.SelectorEventLoop(selectors.SelectSelector())
|
return asyncio.SelectorEventLoop(selectors.SelectSelector())
|
||||||
|
|
||||||
|
|
||||||
def noop(*args):
|
def noop(*args, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -2305,6 +2305,13 @@ class HandleTests(test_utils.TestCase):
|
||||||
% (re.escape(filename), lineno))
|
% (re.escape(filename), lineno))
|
||||||
self.assertRegex(repr(h), regex)
|
self.assertRegex(repr(h), regex)
|
||||||
|
|
||||||
|
# partial function with keyword args
|
||||||
|
cb = functools.partial(noop, x=1)
|
||||||
|
h = asyncio.Handle(cb, (2, 3), self.loop)
|
||||||
|
regex = (r'^<Handle noop\(x=1\)\(2, 3\) at %s:%s>$'
|
||||||
|
% (re.escape(filename), lineno))
|
||||||
|
self.assertRegex(repr(h), regex)
|
||||||
|
|
||||||
# partial method
|
# partial method
|
||||||
if sys.version_info >= (3, 4):
|
if sys.version_info >= (3, 4):
|
||||||
method = HandleTests.test_handle_repr
|
method = HandleTests.test_handle_repr
|
||||||
|
|
|
@ -424,6 +424,9 @@ Library
|
||||||
- Issue #28174: Handle when SO_REUSEPORT isn't properly supported.
|
- Issue #28174: Handle when SO_REUSEPORT isn't properly supported.
|
||||||
Patch by Seth Michael Larson.
|
Patch by Seth Michael Larson.
|
||||||
|
|
||||||
|
- Issue #26654: Inspect functools.partial in asyncio.Handle.__repr__.
|
||||||
|
Patch by iceboy.
|
||||||
|
|
||||||
IDLE
|
IDLE
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue