This documentation covers a development version of IPython. The development version may differ significantly from the latest stable release.
This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.
If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).
- class IPython.core.guarded_eval.EvaluationContext(locals, globals, evaluation, in_subscript)¶
- evaluation: Literal['forbidden', 'minimal', 'limited', 'unsafe', 'dangerous']¶
Evaluation policy identifier
- in_subscript: bool¶
Whether the evalution of code takes place inside of a subscript. Useful for evaluating
- class IPython.core.guarded_eval.GuardRejection¶
Exception raised when guard rejects evaluation attempt.
- IPython.core.guarded_eval.guarded_eval(code: str, context: EvaluationContext)¶
Evaluate provided code in the evaluation context.
If evaluation policy given by context is set to
forbiddenno evaluation will be performed; if it is set to
eval()will be used; finally, for any other, policy
eval_node()will be called on parsed AST.
- IPython.core.guarded_eval.eval_node(node: AST | None, context: EvaluationContext)¶
Evaluate AST node in provided context.
Applies evaluation restrictions defined in the context. Currently does not support evaluation of functions with keyword arguments.
Does not evaluate actions that always have side effects:
class definitions (
class sth: ...)
function definitions (
def sth: ...)
variable assignments (
x = 1)
augmented assignments (
x += 1)
Does not evaluate operations which do not return values:
if x:) except for ternary IfExp (
a if x else b)
The purpose of this function is to guard against unwanted side-effects; it does not give guarantees on protection from malicious code execution.