MCPcopy Index your code
hub / github.com/python/cpython / _run_code

Function _run_code

Lib/runpy.py:65–88  ·  view source on GitHub ↗

Helper to run code in nominated namespace

(code, run_globals, init_globals=None,
              mod_name=None, mod_spec=None,
              pkg_name=None, script_name=None)

Source from the content-addressed store, hash-verified

63
64# TODO: Replace these helpers with importlib._bootstrap_external functions.
65def _run_code(code, run_globals, init_globals=None,
66 mod_name=None, mod_spec=None,
67 pkg_name=None, script_name=None):
68 """Helper to run code in nominated namespace"""
69 if init_globals is not None:
70 run_globals.update(init_globals)
71 if mod_spec is None:
72 loader = None
73 fname = script_name
74 cached = None
75 else:
76 loader = mod_spec.loader
77 fname = mod_spec.origin
78 cached = mod_spec.cached
79 if pkg_name is None:
80 pkg_name = mod_spec.parent
81 run_globals.update(__name__ = mod_name,
82 __file__ = fname,
83 __doc__ = None,
84 __loader__ = loader,
85 __package__ = pkg_name,
86 __spec__ = mod_spec)
87 exec(code, run_globals)
88 return run_globals
89
90def _run_module_code(code, init_globals=None,
91 mod_name=None, mod_spec=None,

Callers 5

create_nsMethod · 0.90
_run_module_codeFunction · 0.85
_run_module_as_mainFunction · 0.85
run_moduleFunction · 0.85
run_pathFunction · 0.85

Calls 1

updateMethod · 0.45

Tested by 1

create_nsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…