py1.runner

Helps running user-provided code and getting readable backtraces.

Functions

build_globals() Returns a dictionary that can be used as globals for exec.
run(code, code_globals) Runs the code with provided globals, improving backtraces readability.

Exceptions

Error Base class for errors from this module.
RunFailed(message) The user-provided code failed.
exception Error[source]

Base class for errors from this module.

exception RunFailed(message)[source]

The user-provided code failed.

build_globals()[source]

Returns a dictionary that can be used as globals for exec.

run(code, code_globals)[source]

Runs the code with provided globals, improving backtraces readability.

Parameters:
  • code – The string or code object to run.
  • code_globals – A dictionary that defines global and local variables.
Raises:

RunFailed – The user-provided code failed, the message will contain a clean backtrace.