diff --git a/CHANGES.rst b/CHANGES.rst index f567534..7f55366 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 e974057..d7c1b9c 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 c030bb7..107be23 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 95054a8..6e0b8d9 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') == ...