From 10ec1e078aef4e94d453c07e90e7f7635749bef1 Mon Sep 17 00:00:00 2001 From: Rasmus Wriedt Larsen Date: Sat, 18 Jul 2020 17:56:56 +0200 Subject: [PATCH] Python: CG trace: Better type hints --- .../recorded-call-graph-metrics/src/cg_trace/tracer.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/tools/recorded-call-graph-metrics/src/cg_trace/tracer.py b/python/tools/recorded-call-graph-metrics/src/cg_trace/tracer.py index 7b039fa637a..3878d3f1849 100644 --- a/python/tools/recorded-call-graph-metrics/src/cg_trace/tracer.py +++ b/python/tools/recorded-call-graph-metrics/src/cg_trace/tracer.py @@ -3,6 +3,7 @@ import dis import logging import os import sys +from types import FrameType from typing import Optional LOGGER = logging.getLogger(__name__) @@ -43,7 +44,7 @@ class Call: inst_index: int @classmethod - def from_frame(cls, frame): + def from_frame(cls, frame: FrameType): code = frame.f_code b = dis.Bytecode(frame.f_code, current_offset=frame.f_lasti) @@ -119,7 +120,7 @@ class PythonCallee(Callee): funcname: str @classmethod - def from_frame(cls, frame): + def from_frame(cls, frame: FrameType): code = frame.f_code return cls( filename=canonic_filename(code.co_filename), @@ -167,7 +168,7 @@ class CallGraphTracer: finally: sys.setprofile(None) - def profilefunc(self, frame, event, arg): + def profilefunc(self, frame: FrameType, event: str, arg): # ignore everything until the first call, since that is `exec` from the `run` # method above if not self.exec_call_seen: