mirror of https://github.com/cool-RR/PySnooper.git
Rewrite get_local_reprs to use sort explicitely
This commit is contained in:
parent
2a6b2b4299
commit
1cd2dffa13
|
@ -21,14 +21,18 @@ ipython_filename_pattern = re.compile('^<ipython-input-([0-9]+)-.*>$')
|
|||
|
||||
|
||||
def get_local_reprs(frame, watch=()):
|
||||
var_names = frame.f_code.co_varnames + frame.f_code.co_cellvars
|
||||
result = collections.OrderedDict(
|
||||
(key, utils.get_shortish_repr(frame.f_locals[key]))
|
||||
for key in var_names if key in frame.f_locals
|
||||
result_items = [(key, utils.get_shortish_repr(value)) for key, value
|
||||
in frame.f_locals.items()]
|
||||
|
||||
vars_order = frame.f_code.co_varnames + frame.f_code.co_cellvars + frame.f_code.co_freevars
|
||||
result_items.sort(
|
||||
key=lambda key_value: (
|
||||
(vars_order.index(key_value[0]) if key_value[0] in vars_order else float("inf")),
|
||||
key_value[0]
|
||||
)
|
||||
)
|
||||
|
||||
result.update((key, utils.get_shortish_repr(frame.f_locals[key]))
|
||||
for key in frame.f_code.co_freevars)
|
||||
result = collections.OrderedDict(result_items)
|
||||
|
||||
for variable in watch:
|
||||
result.update(sorted(variable.items(frame)))
|
||||
|
|
Loading…
Reference in New Issue