From 0488d0ce08b3f3fe5833c22006193ea79334e8e4 Mon Sep 17 00:00:00 2001 From: Jay Marcyes Date: Wed, 23 Nov 2016 18:00:17 -0800 Subject: [PATCH] fixes an error that occured when pout was called from an instance method when that method was called from inside a jinja template macro --- pout.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pout.py b/pout.py index a5da754..ac1f671 100644 --- a/pout.py +++ b/pout.py @@ -47,7 +47,7 @@ # pout2.b("remember to remove pout2") # except ImportError: pass -__version__ = '0.6.1' +__version__ = '0.6.2' logger = logging.getLogger(__name__) @@ -426,16 +426,25 @@ def _get_arg_info(self, arg_vals={}, back_i=0): 'args': [], 'frame': None, 'line': u'Unknown', - 'file': u'Unknown' + 'file': u'Unknown', + 'arg_names': [] } #back_i += 3 # move past the call to the outer frames and the call to this function - frame = inspect.currentframe() - frames = inspect.getouterframes(frame) - back_i = self._find_entry_frame(frames) - - if len(frames) > back_i: - ret_dict.update(self._get_call_info(frames[back_i], __name__, frames[back_i - 1][3])) + try: + frame = inspect.currentframe() + frames = inspect.getouterframes(frame) + back_i = self._find_entry_frame(frames) + + if len(frames) > back_i: + ret_dict.update(self._get_call_info(frames[back_i], __name__, frames[back_i - 1][3])) + + except IndexError: + # There was a very specific bug that would cause inspect.getouterframes(frame) + # to fail when pout was called from an object's method that was called from + # within a Jinja template, it seemed like it was going to be annoying to + # reproduce and so I now catch the IndexError that inspect was throwing + pass # build the arg list if values have been passed in if len(arg_vals) > 0: