Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions guppylang-internals/src/guppylang_internals/frame_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import inspect
from types import FrameType, ModuleType, TracebackType
from types import FrameType, TracebackType


def get_calling_frame(*, skip_main_lang: bool = True) -> FrameType:
Expand All @@ -12,13 +12,13 @@ def get_calling_frame(*, skip_main_lang: bool = True) -> FrameType:
"""
frame = inspect.currentframe()
while frame:
module = inspect.getmodule(frame)
if module is None:
module_name = frame.f_globals.get("__name__")
if module_name is None:
return frame
elif _is_main_lang_module(module):
elif _is_main_lang_module(module_name):
if not skip_main_lang:
return frame
elif _is_internals_module(module):
elif _is_internals_module(module_name):
pass
else:
return frame
Expand All @@ -33,17 +33,18 @@ def remove_internal_frames(tb: TracebackType | None) -> TracebackType | None:
if tb:
module = inspect.getmodule(tb.tb_frame)
if module is not None and (
_is_main_lang_module(module) or _is_internals_module(module)
_is_main_lang_module(module.__name__)
or _is_internals_module(module.__name__)
):
return remove_internal_frames(tb.tb_next)
if tb.tb_next:
tb.tb_next = remove_internal_frames(tb.tb_next)
return tb


def _is_main_lang_module(module: ModuleType) -> bool:
return module.__name__.startswith("guppylang.")
def _is_main_lang_module(module_name: str) -> bool:
return module_name.startswith("guppylang.")


def _is_internals_module(module: ModuleType) -> bool:
return module.__name__.startswith("guppylang_internals.")
def _is_internals_module(module_name: str) -> bool:
return module_name.startswith("guppylang_internals.")
Loading