Show More
@@ -1051,7 +1051,9 b' def _render_signature(obj_signature, obj_name):' | |||
|
1051 | 1051 | # add up name, parameters, braces (2), and commas |
|
1052 | 1052 | if len(obj_name) + sum(len(r) + 2 for r in result) > 75: |
|
1053 | 1053 | # This doesn’t fit behind “Signature: ” in an inspect window. |
|
1054 |
rendered = '{}(\n{})'.format(obj_name, ''.join( |
|
|
1054 | rendered = '{}(\n{})'.format(obj_name, ''.join( | |
|
1055 | ' {},\n'.format(r) for r in result) | |
|
1056 | ) | |
|
1055 | 1057 | else: |
|
1056 | 1058 | rendered = '{}({})'.format(obj_name, ', '.join(result)) |
|
1057 | 1059 |
@@ -5,7 +5,7 b'' | |||
|
5 | 5 | # Distributed under the terms of the Modified BSD License. |
|
6 | 6 | |
|
7 | 7 | |
|
8 | from inspect import Signature, Parameter | |
|
8 | from inspect import signature, Signature, Parameter | |
|
9 | 9 | import os |
|
10 | 10 | import re |
|
11 | 11 | import sys |
@@ -22,7 +22,6 b' from IPython import get_ipython' | |||
|
22 | 22 | from IPython.testing.tools import AssertPrints, AssertNotPrints |
|
23 | 23 | from IPython.utils.path import compress_user |
|
24 | 24 | |
|
25 | ||
|
26 | 25 | #----------------------------------------------------------------------------- |
|
27 | 26 | # Globals and constants |
|
28 | 27 | #----------------------------------------------------------------------------- |
@@ -432,3 +431,33 b' def test_builtin_init():' | |||
|
432 | 431 | init_def = info['init_definition'] |
|
433 | 432 | nt.assert_is_not_none(init_def) |
|
434 | 433 | |
|
434 | ||
|
435 | def test_render_signature_short(): | |
|
436 | def short_fun(a: int = 1): pass | |
|
437 | sig = oinspect._render_signature( | |
|
438 | signature(short_fun), | |
|
439 | short_fun.__name__, | |
|
440 | ) | |
|
441 | nt.assert_equal(sig, 'short_fun(a: int = 1)') | |
|
442 | ||
|
443 | ||
|
444 | def test_render_signature_long(): | |
|
445 | from typing import Optional | |
|
446 | ||
|
447 | def long_function( | |
|
448 | a_really_long_parameter: int, | |
|
449 | and_another_long_one: bool = False, | |
|
450 | let_us_make_sure_this_is_looong: Optional[str] = None, | |
|
451 | ) -> bool: pass | |
|
452 | ||
|
453 | sig = oinspect._render_signature( | |
|
454 | signature(long_function), | |
|
455 | long_function.__name__, | |
|
456 | ) | |
|
457 | nt.assert_equal(sig, '''\ | |
|
458 | long_function( | |
|
459 | a_really_long_parameter: int, | |
|
460 | and_another_long_one: bool = False, | |
|
461 | let_us_make_sure_this_is_looong: Union[str, NoneType] = None, | |
|
462 | ) -> bool\ | |
|
463 | ''') |
General Comments 0
You need to be logged in to leave comments.
Login now