Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/IPython/utils/frame.py: 60%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

10 statements  

1""" 

2Utilities for working with stack frames. 

3""" 

4 

5#----------------------------------------------------------------------------- 

6# Copyright (C) 2008-2011 The IPython Development Team 

7# 

8# Distributed under the terms of the BSD License. The full license is in 

9# the file COPYING, distributed as part of this software. 

10#----------------------------------------------------------------------------- 

11 

12#----------------------------------------------------------------------------- 

13# Imports 

14#----------------------------------------------------------------------------- 

15 

16from __future__ import annotations 

17 

18import sys 

19from types import ModuleType 

20from typing import Any 

21 

22#----------------------------------------------------------------------------- 

23# Code 

24#----------------------------------------------------------------------------- 

25 

26def extract_module_locals(depth: int = 0) -> tuple[ModuleType, dict[str, Any]]: 

27 """Returns (module, locals) of the function `depth` frames away from the caller""" 

28 f = sys._getframe(depth + 1) 

29 global_ns = f.f_globals 

30 module = sys.modules[global_ns['__name__']] 

31 return (module, f.f_locals)