From 141c1732bd99d71d5ba3b34d5c7e82d1adb4e621 Mon Sep 17 00:00:00 2001 From: zedzhen <59135268+zedzhen@users.noreply.github.com> Date: Fri, 24 Apr 2026 12:37:07 +0300 Subject: [PATCH] allow ellipsis --- CHANGES.rst | 2 ++ src/RestrictedPython/Guards.py | 1 + src/RestrictedPython/transformer.py | 10 +--------- tests/transformer/test_base_types.py | 7 +++---- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index f5675348..7f553667 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,8 @@ Changes - Drop support for Python 3.9. +- Allow the ``...`` (Ellipsis) statement. + 8.1 (2025-10-19) ---------------- diff --git a/src/RestrictedPython/Guards.py b/src/RestrictedPython/Guards.py index e974057e..d7c1b9c3 100644 --- a/src/RestrictedPython/Guards.py +++ b/src/RestrictedPython/Guards.py @@ -27,6 +27,7 @@ 'None', 'False', 'True', + 'Ellipsis', 'abs', 'bool', 'bytes', diff --git a/src/RestrictedPython/transformer.py b/src/RestrictedPython/transformer.py index c030bb7d..107be232 100644 --- a/src/RestrictedPython/transformer.py +++ b/src/RestrictedPython/transformer.py @@ -476,20 +476,12 @@ def node_contents_visit(self, node): # ast for Literals def visit_Constant(self, node): - """Allow constant literals with restriction for Ellipsis. + """Allow constant literals. Constant replaces Num, Str, Bytes, NameConstant and Ellipsis in Python 3.8+. :see: https://docs.python.org/dev/whatsnew/3.8.html#deprecated """ - if node.value is Ellipsis: - # Deny using `...`. - # Special handling necessary as ``self.not_allowed(node)`` - # would return the Error Message: - # 'Constant statements are not allowed.' - # which is only partial true. - self.error(node, 'Ellipsis statements are not allowed.') - return return self.node_contents_visit(node) def visit_Interactive(self, node): diff --git a/tests/transformer/test_base_types.py b/tests/transformer/test_base_types.py index 95054a8b..6e0b8d98 100644 --- a/tests/transformer/test_base_types.py +++ b/tests/transformer/test_base_types.py @@ -1,4 +1,3 @@ -from RestrictedPython import compile_restricted_exec from tests.helper import restricted_eval @@ -18,6 +17,6 @@ def test_Set(): def test_Ellipsis(): - """It prevents using the `ellipsis` statement.""" - result = compile_restricted_exec('...') - assert result.errors == ('Line 1: Ellipsis statements are not allowed.',) + """It allows to use the `ellipsis` statement.""" + assert restricted_eval('...') == ... + assert restricted_eval('Ellipsis') == ...