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

Function run_code

Lib/test/support/__init__.py:818–824  ·  view source on GitHub ↗

Run a piece of code after dedenting it, and return its global namespace.

(code: str, extra_names: dict[str, object] | None = None)

Source from the content-addressed store, hash-verified

816
817
818def run_code(code: str, extra_names: dict[str, object] | None = None) -> dict[str, object]:
819 """Run a piece of code after dedenting it, and return its global namespace."""
820 ns = {}
821 if extra_names:
822 ns.update(extra_names)
823 exec(textwrap.dedent(code), ns)
824 return ns
825
826
827def check_syntax_error(testcase, statement, errtext='', *, lineno=None, offset=None):

Callers 15

build_moduleFunction · 0.90
checkMethod · 0.90
test_moduleMethod · 0.90
test_set_annotationsMethod · 0.90
check_scopesMethod · 0.90
_make_tdMethod · 0.90

Calls 2

updateMethod · 0.45
dedentMethod · 0.45

Tested by 15

build_moduleFunction · 0.72
checkMethod · 0.72
test_moduleMethod · 0.72
test_set_annotationsMethod · 0.72
check_scopesMethod · 0.72
_make_tdMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…