Python: CG trace: Better type hints

This commit is contained in:
Rasmus Wriedt Larsen
2020-07-18 17:56:56 +02:00
parent 8b6de17461
commit 10ec1e078a

View File

@@ -3,6 +3,7 @@ import dis
import logging import logging
import os import os
import sys import sys
from types import FrameType
from typing import Optional from typing import Optional
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
@@ -43,7 +44,7 @@ class Call:
inst_index: int inst_index: int
@classmethod @classmethod
def from_frame(cls, frame): def from_frame(cls, frame: FrameType):
code = frame.f_code code = frame.f_code
b = dis.Bytecode(frame.f_code, current_offset=frame.f_lasti) b = dis.Bytecode(frame.f_code, current_offset=frame.f_lasti)
@@ -119,7 +120,7 @@ class PythonCallee(Callee):
funcname: str funcname: str
@classmethod @classmethod
def from_frame(cls, frame): def from_frame(cls, frame: FrameType):
code = frame.f_code code = frame.f_code
return cls( return cls(
filename=canonic_filename(code.co_filename), filename=canonic_filename(code.co_filename),
@@ -167,7 +168,7 @@ class CallGraphTracer:
finally: finally:
sys.setprofile(None) 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` # ignore everything until the first call, since that is `exec` from the `run`
# method above # method above
if not self.exec_call_seen: if not self.exec_call_seen: