Repository: ipython/ipython

Issue:
Define a better displayFormatter of function and methods
I think it should be possible to define a default formatter for functions that would be better than the defautl one. 

The following is not really useful:

```
In [1]: from inspect import signature
In [2]: signature
Out[2]: <function inspect.signature>
```

Something that would display less than `signature?` or `signature??`, but still a bit better than plain function/methods REPR. 

```
In [1]: from inspect import signature
In [2]: signature
Out[2]: <function inspect.signature(obj, *, follow_wrapped=True)>
```

Seem like a nice standalone project that could be useful. 

Thoughts ?



Discussion:
Yep, I think that would make sense.

I'm trying this for Hacktoberfest!

Resolving patch:
diff --git a/IPython/lib/pretty.py b/IPython/lib/pretty.py
--- a/IPython/lib/pretty.py
+++ b/IPython/lib/pretty.py
@@ -88,7 +88,7 @@ def _repr_pretty_(self, p, cycle):
 
 from IPython.utils.decorators import undoc
 from IPython.utils.py3compat import PYPY
-
+from IPython.utils.signatures import signature
 
 __all__ = ['pretty', 'pprint', 'PrettyPrinter', 'RepresentationPrinter',
     'for_type', 'for_type_by_name']
@@ -711,7 +711,11 @@ def _function_pprint(obj, p, cycle):
     mod = obj.__module__
     if mod and mod not in ('__builtin__', 'builtins', 'exceptions'):
         name = mod + '.' + name
-    p.text('<function %s>' % name)
+    try:
+       func_def = name + str(signature(obj))
+    except ValueError:
+       func_def = name
+    p.text('<function %s>' % func_def)
 
 
 def _exception_pprint(obj, p, cycle):


Test patch:
diff --git a/IPython/core/tests/test_oinspect.py b/IPython/core/tests/test_oinspect.py
--- a/IPython/core/tests/test_oinspect.py
+++ b/IPython/core/tests/test_oinspect.py
@@ -305,8 +305,13 @@ def test_empty_property_has_no_source():
 
 
 def test_property_sources():
-    import zlib
-
+    import posixpath 
+    # A simple adder whose source and signature stays
+    # the same across Python distributions
+    def simple_add(a, b):
+        "Adds two numbers"
+        return a + b
+    
     class A(object):
         @property
         def foo(self):
@@ -314,18 +319,18 @@ def foo(self):
 
         foo = foo.setter(lambda self, v: setattr(self, 'bar', v))
 
-        id = property(id)
-        compress = property(zlib.compress)
+        dname = property(posixpath.dirname)
+        adder = property(simple_add) 
 
     i = inspector.info(A.foo, detail_level=1)
     nt.assert_in('def foo(self):', i['source'])
     nt.assert_in('lambda self, v:', i['source'])
 
-    i = inspector.info(A.id, detail_level=1)
-    nt.assert_in('fget = <function id>', i['source'])
-
-    i = inspector.info(A.compress, detail_level=1)
-    nt.assert_in('fget = <function zlib.compress>', i['source'])
+    i = inspector.info(A.dname, detail_level=1)
+    nt.assert_in('def dirname(p)', i['source'])
+    
+    i = inspector.info(A.adder, detail_level=1)
+    nt.assert_in('def simple_add(a, b)', i['source'])
 
 
 def test_property_docstring_is_in_info_for_detail_level_0():
diff --git a/IPython/lib/tests/test_pretty.py b/IPython/lib/tests/test_pretty.py
--- a/IPython/lib/tests/test_pretty.py
+++ b/IPython/lib/tests/test_pretty.py
@@ -405,3 +405,19 @@ def test_mappingproxy():
     ]
     for obj, expected in cases:
         nt.assert_equal(pretty.pretty(obj), expected)
+
+def test_function_pretty():
+    "Test pretty print of function"
+    # posixpath is a pure python module, its interface is consistent
+    # across Python distributions
+    import posixpath
+    nt.assert_equal(pretty.pretty(posixpath.join), '<function posixpath.join(a, *p)>')
+ 
+    # custom function
+    def meaning_of_life(question=None):
+        if question:
+            return 42
+        return "Don't panic"
+
+    nt.assert_in('meaning_of_life(question=None)', pretty.pretty(meaning_of_life))
+