##// END OF EJS Templates
Merge pull request #10863 from Madhu94/add-function-signature-display...
Thomas Kluyver -
r24032:dc9d1c67 merge
parent child Browse files
Show More
@@ -305,8 +305,13 b' def test_empty_property_has_no_source():'
305
305
306
306
307 def test_property_sources():
307 def test_property_sources():
308 import zlib
308 import posixpath
309
309 # A simple adder whose source and signature stays
310 # the same across Python distributions
311 def simple_add(a, b):
312 "Adds two numbers"
313 return a + b
314
310 class A(object):
315 class A(object):
311 @property
316 @property
312 def foo(self):
317 def foo(self):
@@ -314,18 +319,18 b' def test_property_sources():'
314
319
315 foo = foo.setter(lambda self, v: setattr(self, 'bar', v))
320 foo = foo.setter(lambda self, v: setattr(self, 'bar', v))
316
321
317 id = property(id)
322 dname = property(posixpath.dirname)
318 compress = property(zlib.compress)
323 adder = property(simple_add)
319
324
320 i = inspector.info(A.foo, detail_level=1)
325 i = inspector.info(A.foo, detail_level=1)
321 nt.assert_in('def foo(self):', i['source'])
326 nt.assert_in('def foo(self):', i['source'])
322 nt.assert_in('lambda self, v:', i['source'])
327 nt.assert_in('lambda self, v:', i['source'])
323
328
324 i = inspector.info(A.id, detail_level=1)
329 i = inspector.info(A.dname, detail_level=1)
325 nt.assert_in('fget = <function id>', i['source'])
330 nt.assert_in('def dirname(p)', i['source'])
326
331
327 i = inspector.info(A.compress, detail_level=1)
332 i = inspector.info(A.adder, detail_level=1)
328 nt.assert_in('fget = <function zlib.compress>', i['source'])
333 nt.assert_in('def simple_add(a, b)', i['source'])
329
334
330
335
331 def test_property_docstring_is_in_info_for_detail_level_0():
336 def test_property_docstring_is_in_info_for_detail_level_0():
@@ -88,7 +88,7 b' from warnings import warn'
88
88
89 from IPython.utils.decorators import undoc
89 from IPython.utils.decorators import undoc
90 from IPython.utils.py3compat import PYPY
90 from IPython.utils.py3compat import PYPY
91
91 from IPython.utils.signatures import signature
92
92
93 __all__ = ['pretty', 'pprint', 'PrettyPrinter', 'RepresentationPrinter',
93 __all__ = ['pretty', 'pprint', 'PrettyPrinter', 'RepresentationPrinter',
94 'for_type', 'for_type_by_name']
94 'for_type', 'for_type_by_name']
@@ -711,7 +711,11 b' def _function_pprint(obj, p, cycle):'
711 mod = obj.__module__
711 mod = obj.__module__
712 if mod and mod not in ('__builtin__', 'builtins', 'exceptions'):
712 if mod and mod not in ('__builtin__', 'builtins', 'exceptions'):
713 name = mod + '.' + name
713 name = mod + '.' + name
714 p.text('<function %s>' % name)
714 try:
715 func_def = name + str(signature(obj))
716 except ValueError:
717 func_def = name
718 p.text('<function %s>' % func_def)
715
719
716
720
717 def _exception_pprint(obj, p, cycle):
721 def _exception_pprint(obj, p, cycle):
@@ -405,3 +405,19 b' def test_mappingproxy():'
405 ]
405 ]
406 for obj, expected in cases:
406 for obj, expected in cases:
407 nt.assert_equal(pretty.pretty(obj), expected)
407 nt.assert_equal(pretty.pretty(obj), expected)
408
409 def test_function_pretty():
410 "Test pretty print of function"
411 # posixpath is a pure python module, its interface is consistent
412 # across Python distributions
413 import posixpath
414 nt.assert_equal(pretty.pretty(posixpath.join), '<function posixpath.join(a, *p)>')
415
416 # custom function
417 def meaning_of_life(question=None):
418 if question:
419 return 42
420 return "Don't panic"
421
422 nt.assert_in('meaning_of_life(question=None)', pretty.pretty(meaning_of_life))
423
General Comments 0
You need to be logged in to leave comments. Login now