Skip to content

Commit

Permalink
Expand record return values for all function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech committed Aug 28, 2020
1 parent e30db28 commit 297f6c1
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions record_api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
context_manager: Optional[ContextManager] = None
write_line: Optional[Callable[[dict], None]] = None

FUNCTION_CALL_OP_NAMES = {
"CALL_METHOD",
"CALL_FUNCTION",
"CALL_FUNCTION_KW",
"CALL_FUNCTION_EX",
}


def get_tracer() -> Tracer:
global TRACER
Expand Down Expand Up @@ -400,7 +407,8 @@ def __call__(self) -> None:
return self.process(
(self.TOS, self.TOS1), BINARY_OPS[opname], (self.TOS1, self.TOS)
)
if self.previous_stack and self.previous_stack.opname == "CALL_METHOD":

if self.previous_stack and self.previous_stack.opname in FUNCTION_CALL_OP_NAMES:
self.log_called_method()

method_name = f"op_{opname}"
Expand All @@ -409,15 +417,16 @@ def __call__(self) -> None:
return None

def log_called_method(self):
filename, line, fn, args, *kwargs = self.previous_stack.log_call_args
kwargs = kwargs[0] if kwargs else {}
log_call(
f"{filename}:{line}",
fn,
tuple(args),
*((kwargs,) if kwargs else ()),
return_type=type(self.TOS),
)
if self.previous_stack.log_call_args:
filename, line, fn, args, *kwargs = self.previous_stack.log_call_args
kwargs = kwargs[0] if kwargs else {}
log_call(
f"{filename}:{line}",
fn,
tuple(args),
*((kwargs,) if kwargs else ()),
return_type=type(self.TOS),
)

# special case subscr b/c we only check first arg, not both
def op_BINARY_SUBSCR(self):
Expand Down Expand Up @@ -489,7 +498,7 @@ def op_COMPARE_OP(self):
def op_CALL_FUNCTION(self):
args = self.pop_n(self.oparg)
fn = self.pop()
self.process((fn,), fn, args)
self.process((fn,), fn, args, delay=True)

def op_CALL_FUNCTION_KW(self):
kwargs_keys = self.pop()
Expand All @@ -499,7 +508,7 @@ def op_CALL_FUNCTION_KW(self):
args = self.pop_n(self.oparg - n_kwargs)
fn = self.pop()

self.process((fn,), fn, args, kwargs)
self.process((fn,), fn, args, kwargs, delay=True)

def op_CALL_FUNCTION_EX(self):
has_kwarg = self.oparg & int("01", 2)
Expand All @@ -513,7 +522,7 @@ def op_CALL_FUNCTION_EX(self):
fn = self.pop()
if inspect.isgenerator(args):
return
self.process((fn,), fn, args, kwargs)
self.process((fn,), fn, args, kwargs, delay=True)

def op_CALL_METHOD(self):
args = self.pop_n(self.oparg)
Expand Down

0 comments on commit 297f6c1

Please sign in to comment.