From 754cd81b173ff202566b6bccffa699a49e3047bd Mon Sep 17 00:00:00 2001 From: Undefeated-man <51683546+Undefeated-man@users.noreply.github.com> Date: Mon, 26 Jul 2021 17:50:58 +0800 Subject: [PATCH] fix an indent bugs and add some new functions 1) make it available to identify which file the called function belongs to when our traceback depth>1 -- automatically add the name of file after the {indent} 2) adding "\n" before each "newish_string" and "Source path: xxx" to make the output nicer and easier to look 3) indent mistakes is at line 363-364 in "tracer.py" --- pysnooper/tracer.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pysnooper/tracer.py b/pysnooper/tracer.py index 56165d3..0bb71b5 100644 --- a/pysnooper/tracer.py +++ b/pysnooper/tracer.py @@ -360,8 +360,8 @@ class Tracer: return None elif _frame_candidate.f_code in self.target_codes or _frame_candidate in self.target_frames: break - else: - return None + else: + return None if event == 'call': thread_global.depth += 1 @@ -394,7 +394,7 @@ class Tracer: source_path, source = get_path_and_source_from_frame(frame) source_path = source_path if not self.normalize else os.path.basename(source_path) if self.last_source_path != source_path: - self.write(u'{indent}Source path:... {source_path}'. + self.write(u'\n{indent}Source path:... {source_path}'. format(**locals())) self.last_source_path = source_path source_line = source[line_no - 1] @@ -422,11 +422,15 @@ class Tracer: 'New var:....... ') for name, value_repr in local_reprs.items(): + if self.depth > 1: + file_name = sys._getframe().f_code.co_filename.split(os.sep)[-1] + " " + else: + file_name = "" if name not in old_local_reprs: - self.write('{indent}{newish_string}{name} = {value_repr}'.format( + self.write('{indent}{file_name}{newish_string}{name} = {value_repr}\n'.format( **locals())) elif old_local_reprs[name] != value_repr: - self.write('{indent}Modified var:.. {name} = {value_repr}'.format( + self.write('{indent}{file_name}Modified var:.. {name} = {value_repr}\n'.format( **locals())) # #