From 84f40733f31ee473375fc00bac560e2851051a0c 2011-07-18 22:31:42 From: Ben Edwards Date: 2011-07-18 22:31:42 Subject: [PATCH] Display source code correctly for decorated functions. If a function is decorated with a decorator which itself has been decorated using @decorator, currently the no source code is displayed when '??' is used. This checks to see if the function has a __wrapped__ attribate (added by @decorator) and appropriately displays the source for that object. --- diff --git a/IPython/core/oinspect.py b/IPython/core/oinspect.py index be80b67..67a557d 100644 --- a/IPython/core/oinspect.py +++ b/IPython/core/oinspect.py @@ -129,10 +129,13 @@ def getsource(obj,is_binary=False): - is_binary: whether the object is known to come from a binary source. This implementation will skip returning any output for binary objects, but custom extractors may know how to meaningfully process them.""" - + if is_binary: return None else: + #get source if obj was decoratred with @decorator + if hasattr(obj,"__wrapped__"): + obj = obj.__wrapped__ try: src = inspect.getsource(obj) except TypeError: