mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-23 10:15:11 +00:00
Massaging some code
This commit is contained in:
parent
c9a51de674
commit
e21fc11352
3 changed files with 12 additions and 13 deletions
|
|
@ -27,9 +27,11 @@ def get_shortish_repr(item):
|
|||
def get_local_reprs(frame, variables=()):
|
||||
result = {key: get_shortish_repr(value) for key, value
|
||||
in frame.f_locals.items()}
|
||||
for variable, code in variables:
|
||||
for variable in variables:
|
||||
try:
|
||||
result[variable] = eval(code, frame.f_globals, frame.f_locals)
|
||||
result[variable] = get_shortish_repr(
|
||||
eval(variable, frame.f_globals, frame.f_locals)
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return result
|
||||
|
|
@ -117,11 +119,8 @@ class Tracer:
|
|||
self._write = write
|
||||
self.truncate = truncate
|
||||
if isinstance(variables, six.string_types):
|
||||
variables = [variables]
|
||||
self.variables = [
|
||||
(v, compile(v, target_code_object.co_filename, 'eval'))
|
||||
for v in variables
|
||||
]
|
||||
variables = (variables,)
|
||||
self.variables = variables
|
||||
self.frame_to_old_local_reprs = collections.defaultdict(lambda: {})
|
||||
self.frame_to_local_reprs = collections.defaultdict(lambda: {})
|
||||
self.depth = depth
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ def test_variables():
|
|||
|
||||
@pysnooper.snoop(variables=(
|
||||
'foo.x',
|
||||
'io.__name__',
|
||||
'io.__name__',
|
||||
'len(foo.__dict__["x"] * "abc")',
|
||||
))
|
||||
def my_function():
|
||||
|
|
@ -71,22 +71,22 @@ def test_variables():
|
|||
output,
|
||||
(
|
||||
VariableEntry('Foo'),
|
||||
VariableEntry('io.__name__', 'io'),
|
||||
VariableEntry('io.__name__', "'io'"),
|
||||
CallEntry('def my_function():'),
|
||||
LineEntry('foo = Foo()'),
|
||||
VariableEntry('foo'),
|
||||
VariableEntry('foo.x', '2'),
|
||||
VariableEntry('len(foo.__dict__["x"] * "abc")', 6),
|
||||
VariableEntry('len(foo.__dict__["x"] * "abc")', '6'),
|
||||
LineEntry(),
|
||||
VariableEntry('i', '0'),
|
||||
LineEntry(),
|
||||
VariableEntry('foo.x', '4'),
|
||||
VariableEntry('len(foo.__dict__["x"] * "abc")', 12),
|
||||
VariableEntry('len(foo.__dict__["x"] * "abc")', '12'),
|
||||
LineEntry(),
|
||||
VariableEntry('i', '1'),
|
||||
LineEntry(),
|
||||
VariableEntry('foo.x', '16'),
|
||||
VariableEntry('len(foo.__dict__["x"] * "abc")', 48),
|
||||
VariableEntry('len(foo.__dict__["x"] * "abc")', '48'),
|
||||
LineEntry(),
|
||||
ReturnEntry(),
|
||||
ReturnValueEntry('None')
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ class VariableEntry(_BaseValueEntry):
|
|||
|
||||
def _check_value(self, value):
|
||||
if self.value is not None:
|
||||
return value == str(self.value)
|
||||
return value == self.value
|
||||
elif self.value_regex is not None:
|
||||
return self.value_regex.match(value)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue