Skip to content

Commit

Permalink
Fix breaking Python 3.9.0a5.
Browse files Browse the repository at this point in the history
Fixes #193.
  • Loading branch information
Michael Howitz committed Mar 31, 2020
1 parent 33c1e95 commit ad32fb1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
8 changes: 6 additions & 2 deletions docs/CHANGES.rst
@@ -1,12 +1,16 @@
Changes
=======

5.1 (unreleased)
----------------
5.1a0 (unreleased)
------------------

- Drop install dependency on ``setuptools``.
(`#189 <https://github.com/zopefoundation/RestrictedPython/issues/189>`_)

- Start supporting Python 3.9.0a5. (Be aware that this support currently only
makes RestrictedPython usable on Python 3.9. The security implications of
using Python 3.9 have not yet been checked.)


5.0 (2019-09-03)
----------------
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -32,7 +32,7 @@ def read(*rnames):

setup(
name='RestrictedPython',
version='5.1.dev0',
version='5.1a0.dev0',
url='https://github.com/zopefoundation/RestrictedPython',
license='ZPL 2.1',
description=(
Expand Down Expand Up @@ -70,7 +70,7 @@ def read(*rnames):
package_dir={'': 'src'},
install_requires=[
],
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.9", # NOQA: E501
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.10", # NOQA: E501
tests_require=tests_require,
extras_require={
'test': tests_require,
Expand Down
3 changes: 3 additions & 0 deletions src/RestrictedPython/transformer.py
Expand Up @@ -355,6 +355,9 @@ def transform_slice(self, slice_):
if isinstance(slice_, ast.Index):
return slice_.value

elif isinstance(slice_, ast.Name): # Python 3.9.0a5+ for a[b]
return slice_

elif isinstance(slice_, ast.Slice):
# Create a python slice object.
args = []
Expand Down
17 changes: 17 additions & 0 deletions tests/transformer/test_subscript.py
Expand Up @@ -17,6 +17,23 @@ def test_read_simple_subscript(mocker):
assert (value, 'b') == glb['simple_subscript'](value)


VAR_SUBSCRIPT = """
def simple_subscript(a, b):
return a[b]
"""


def test_read_subscript_with_variable(mocker):
value = [1]
idx = 0
_getitem_ = mocker.stub()
_getitem_.side_effect = lambda ob, index: (ob, index)
glb = {'_getitem_': _getitem_}
restricted_exec(VAR_SUBSCRIPT, glb)

assert (value, 0) == glb['simple_subscript'](value, idx)


TUPLE_SUBSCRIPTS = """
def tuple_subscript(a):
return a[1, 2]
Expand Down

0 comments on commit ad32fb1

Please sign in to comment.