Skip to content

Commit

Permalink
Fix breaking Python 3.9.0a5. (#194)
Browse files Browse the repository at this point in the history
Handling of slices has been changed.

Co-authored-by: dieter <dieter@handshake.de>
  • Loading branch information
Michael Howitz and d-maurer committed Apr 3, 2020
1 parent 33c1e95 commit 4833538
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -18,6 +18,8 @@ matrix:
env: TOXENV=py37,py37-datetime
- python: "3.8"
env: TOXENV=py38,py38-datetime
- python: "3.9-dev"
env: TOXENV=py39,py39-datetime

before_install:
- travis_retry pip install -U -c constraints.txt coveralls coverage
Expand Down
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
6 changes: 5 additions & 1 deletion src/RestrictedPython/transformer.py
Expand Up @@ -352,7 +352,11 @@ def transform_slice(self, slice_):
Conversion is done by calling the 'slice' function from builtins
"""

if isinstance(slice_, ast.Index):
if isinstance(slice_, ast.expr):
# Python 3.9+
return slice_

elif isinstance(slice_, ast.Index):
return slice_.value

elif isinstance(slice_, ast.Slice):
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
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -6,6 +6,7 @@ envlist =
py36-datetime,
py37,
py38,
py39,
docs,
lint,
coverage,
Expand Down

0 comments on commit 4833538

Please sign in to comment.