Optional[FrameType] has no attribute "f_code" #1217
-
I want to identify the current executing function during runtime using the Python inspect() function (https://docs.python.org/3/library/inspect.html). The code and mypy error are:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
inspect.currentframe() can depending on the python implementation return None as stated in the documentation:
mypy is just letting you know that's the case. To handle this you can just check if the return of currentframe() is None from types import FrameType
frame = inspect.currentframe()
if frame is None:
raise RuntimeError("unsupported python implementation") # or give a default name
fn_name: str = frame.f_code.co_name |
Beta Was this translation helpful? Give feedback.
inspect.currentframe() can depending on the python implementation return None as stated in the documentation:
mypy is just letting you know that's the case. To handle this you can just check if the return of currentframe() is None