From e3688e4b630c53e5e6fc33bbe76e25084d543811 Mon Sep 17 00:00:00 2001 From: Ram Rachum Date: Wed, 1 May 2019 16:21:35 +0300 Subject: [PATCH] Prefer dotted import --- pysnooper/tracer.py | 11 ++++++----- pysnooper/variables.py | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pysnooper/tracer.py b/pysnooper/tracer.py index a95c17d..7bf507f 100644 --- a/pysnooper/tracer.py +++ b/pysnooper/tracer.py @@ -9,13 +9,14 @@ import itertools from .variables import CommonVariable, Exploded, BaseVariable from .third_party import six -from .utils import get_shortish_repr, ensure_tuple +from . import utils + ipython_filename_pattern = re.compile('^$') def get_local_reprs(frame, variables=()): - result = {key: get_shortish_repr(value) for key, value + result = {key: utils.get_shortish_repr(value) for key, value in frame.f_locals.items()} for variable in variables: result.update(variable.items(frame)) @@ -105,10 +106,10 @@ class Tracer: self.truncate = truncate self.variables = [ v if isinstance(v, BaseVariable) else CommonVariable(v) - for v in ensure_tuple(variables) + for v in utils.ensure_tuple(variables) ] + [ v if isinstance(v, BaseVariable) else Exploded(v) - for v in ensure_tuple(exploded_variables) + for v in utils.ensure_tuple(exploded_variables) ] self.frame_to_old_local_reprs = collections.defaultdict(lambda: {}) self.frame_to_local_reprs = collections.defaultdict(lambda: {}) @@ -219,7 +220,7 @@ class Tracer: u'{line_no:4} {source_line}'.format(**locals())) if event == 'return': - return_value_repr = get_shortish_repr(arg) + return_value_repr = utils.get_shortish_repr(arg) self.write('{indent}Return value:.. {return_value_repr}'. format(**locals())) diff --git a/pysnooper/variables.py b/pysnooper/variables.py index 2ceb0fb..89ba45d 100644 --- a/pysnooper/variables.py +++ b/pysnooper/variables.py @@ -2,13 +2,13 @@ import itertools from collections import Mapping, Sequence from copy import deepcopy -from .utils import get_shortish_repr, ensure_tuple +from . import utils class BaseVariable(object): def __init__(self, source, exclude=()): self.source = source - self.exclude = ensure_tuple(exclude) + self.exclude = utils.ensure_tuple(exclude) self.code = compile(source, '', 'eval') def items(self, frame): @@ -24,7 +24,7 @@ class BaseVariable(object): class CommonVariable(BaseVariable): def _items(self, main_value): - result = [(self.source, get_shortish_repr(main_value))] + result = [(self.source, utils.get_shortish_repr(main_value))] for key in self._safe_keys(main_value): try: if key in self.exclude: @@ -34,7 +34,7 @@ class CommonVariable(BaseVariable): continue result.append(( '({}){}'.format(self.source, self._format_key(key)), - get_shortish_repr(value) + utils.get_shortish_repr(value) )) return result @@ -74,7 +74,7 @@ class Keys(CommonVariable): return main_value.keys() def _format_key(self, key): - return '[{}]'.format(get_shortish_repr(key)) + return '[{}]'.format(utils.get_shortish_repr(key)) def _get_value(self, main_value, key): return main_value[key]