From 35cfc053c924356daf652a284717cebb1147a1ff Mon Sep 17 00:00:00 2001 From: zedzhen <59135268+zedzhen@users.noreply.github.com> Date: Tue, 16 Jun 2026 16:42:22 +0300 Subject: [PATCH 1/2] disallow mode="function" in compile_restricted --- CHANGES.rst | 1 + docs/usage/api.rst | 2 +- src/RestrictedPython/compile.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8230a3a..2776dbb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,7 @@ Changes ---------------- - Allow ``ast.Module``, ``ast.Expression`` and ``ast.Interactive`` as body in compile_restricted_function +- Disallow ``mode="function"`` in ``compile_restricted`` (it never worked). 8.3 (2026-06-16) ---------------- diff --git a/docs/usage/api.rst b/docs/usage/api.rst index 2a23e42..966aaaf 100644 --- a/docs/usage/api.rst +++ b/docs/usage/api.rst @@ -11,7 +11,7 @@ API overview :param source: (required). the source code that should be compiled :param filename: (optional). defaults to ``''`` - :param mode: (optional). Use ``'exec'``, ``'eval'``, ``'single'`` or ``'function'``. defaults to ``'exec'`` + :param mode: (optional). Use ``'exec'``, ``'eval'`` or ``'single'``. defaults to ``'exec'`` :param flags: (optional). defaults to ``0`` :param dont_inherit: (optional). defaults to ``False`` :param policy: (optional). defaults to ``RestrictingNodeTransformer`` diff --git a/src/RestrictedPython/compile.py b/src/RestrictedPython/compile.py index e95b970..244f6b6 100644 --- a/src/RestrictedPython/compile.py +++ b/src/RestrictedPython/compile.py @@ -206,7 +206,7 @@ def compile_restricted( policy ... `ast.NodeTransformer` class defining the restrictions. """ - if mode in ['exec', 'eval', 'single', 'function']: + if mode in ['exec', 'eval', 'single']: result = _compile_restricted_mode( source, filename=filename, From b78681895b95875fda2613954a9c3e88a845ff1b Mon Sep 17 00:00:00 2001 From: zedzhen <59135268+zedzhen@users.noreply.github.com> Date: Tue, 16 Jun 2026 16:46:37 +0300 Subject: [PATCH 2/2] style fix --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 2776dbb..3808d7f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,7 @@ Changes ---------------- - Allow ``ast.Module``, ``ast.Expression`` and ``ast.Interactive`` as body in compile_restricted_function + - Disallow ``mode="function"`` in ``compile_restricted`` (it never worked). 8.3 (2026-06-16)