diff --git a/IPython/core/oinspect.py b/IPython/core/oinspect.py index f6dc1f6..4005400 100644 --- a/IPython/core/oinspect.py +++ b/IPython/core/oinspect.py @@ -1051,7 +1051,9 @@ def _render_signature(obj_signature, obj_name): # add up name, parameters, braces (2), and commas if len(obj_name) + sum(len(r) + 2 for r in result) > 75: # This doesn’t fit behind “Signature: ” in an inspect window. - rendered = '{}(\n{})'.format(obj_name, ''.join(' {},\n'.format(result))) + rendered = '{}(\n{})'.format(obj_name, ''.join( + ' {},\n'.format(r) for r in result) + ) else: rendered = '{}({})'.format(obj_name, ', '.join(result)) diff --git a/IPython/core/tests/test_oinspect.py b/IPython/core/tests/test_oinspect.py index 06d6d5a..b3e2b21 100644 --- a/IPython/core/tests/test_oinspect.py +++ b/IPython/core/tests/test_oinspect.py @@ -5,7 +5,7 @@ # Distributed under the terms of the Modified BSD License. -from inspect import Signature, Parameter +from inspect import signature, Signature, Parameter import os import re import sys @@ -22,7 +22,6 @@ from IPython import get_ipython from IPython.testing.tools import AssertPrints, AssertNotPrints from IPython.utils.path import compress_user - #----------------------------------------------------------------------------- # Globals and constants #----------------------------------------------------------------------------- @@ -432,3 +431,33 @@ def test_builtin_init(): init_def = info['init_definition'] nt.assert_is_not_none(init_def) + +def test_render_signature_short(): + def short_fun(a: int = 1): pass + sig = oinspect._render_signature( + signature(short_fun), + short_fun.__name__, + ) + nt.assert_equal(sig, 'short_fun(a: int = 1)') + + +def test_render_signature_long(): + from typing import Optional + + def long_function( + a_really_long_parameter: int, + and_another_long_one: bool = False, + let_us_make_sure_this_is_looong: Optional[str] = None, + ) -> bool: pass + + sig = oinspect._render_signature( + signature(long_function), + long_function.__name__, + ) + nt.assert_equal(sig, '''\ +long_function( + a_really_long_parameter: int, + and_another_long_one: bool = False, + let_us_make_sure_this_is_looong: Union[str, NoneType] = None, +) -> bool\ +''')