mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-23 10:15:11 +00:00
Prefer dotted import
This commit is contained in:
parent
18e758b0f9
commit
e3688e4b63
2 changed files with 11 additions and 10 deletions
|
|
@ -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('^<ipython-input-([0-9]+)-.*>$')
|
||||
|
||||
|
||||
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()))
|
||||
|
||||
|
|
|
|||
|
|
@ -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, '<variable>', '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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue