Avoid global variables; use function parameters or class attributes for better scope management
# Directly access the module name from the frame's global variables
1import inspect2from typing import cast345def is_caller_internal(depth: int = 2) -> bool:6 """Return whether the caller at `depth` of this function is internal."""7 try:8 frame = inspect.currentframe()9 except AttributeError:10 return False11 if frame is None:12 return False13 try:14 for _ in range(depth):15 frame = frame.f_back16 if frame is None:17 return False18 # Directly access the module name from the frame's global variables19 module_globals = frame.f_globals20 caller_module_name = cast("str", module_globals.get("__name__", ""))21 return caller_module_name.startswith("langchain")22 finally:23 del frame
Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.