Commits

Brodie Rao committed c564c47

Added function argument output

Comments (0)

Files changed (1)

tipper/__init__.py

 """
 
 import datetime
+import inspect
 import linecache
 import os
 import pprint
         except Exception:
             return object.__repr__(obj)[:-1] + ' (bad repr)>'
 
+def spformat(obj, depth=None):
+    return SafePrettyPrinter(indent=1, width=76, depth=depth).pformat(obj)
+
+def formatvalue(v):
+    s = spformat(v, depth=1).replace('\n', '')
+    if len(s) > 250:
+        s = object.__repr__(v)[:-1] + ' (really long repr)>'
+    return '=' + s
+
 def stack_with_locals(f):
     if hasattr(sys, 'tracebacklimit'):
         limit = sys.tracebacklimit
     while f is not None and (limit is None or n < limit):
         lineno, co = f.f_lineno, f.f_code
         name, filename = co.co_name, co.co_filename
+        args = inspect.getargvalues(f)
 
         linecache.checkcache(filename)
         line = linecache.getline(filename, lineno, f.f_globals)
         else:
             line = None
 
-        frames.append((filename, lineno, name, line, f.f_locals))
+        frames.append((filename, lineno, name, line, f.f_locals, args))
         f = f.f_back
         n += 1
         frames.reverse()
 
     out = []
-    for filename, lineno, name, line, localvars in frames:
+    for filename, lineno, name, line, localvars, args in frames:
         out.append('  File "%s", line %d, in %s' % (filename, lineno, name))
         if line:
             out.append('    %s' % line.strip())
+
+        args = inspect.formatargvalues(*args, formatvalue=formatvalue)
+        out.append('\n    Arguments: %s%s' % (name, args))
+
         if localvars:
-            out.append('')
+            out.append('    Local variables:\n')
             try:
-                reprs = SafePrettyPrinter(indent=1, width=76,
-                                          depth=None).pformat(localvars)
+                reprs = spformat(localvars)
             except Exception:
                 reprs = "failed to format local variables"
             out += ['    ' + l for l in reprs.splitlines()]