Skip to content

Commit 93cd471

Browse files
author
Michael Howitz
authored
Update to Python 3.10 (#215)
* Configuring for pure-python * Fix tests on Python 3.10.
1 parent 1814aaa commit 93cd471

File tree

8 files changed

+41
-19
lines changed

8 files changed

+41
-19
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
- ["3.7", "py37"]
2929
- ["3.8", "py38"]
3030
- ["3.9", "py39"]
31+
- ["3.10.0-rc.2", "py310"]
3132
- ["3.8", "docs"]
3233
- ["3.8", "coverage"]
3334
- ["3.8", "py38-datetime"]

.meta.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
33
[meta]
44
template = "pure-python"
5-
commit-id = "81a3fca06e30c8fba7256352591a7a298d676a41"
5+
commit-id = "3329f708f7922fcee2608b4057a3976ee4ed6d72"
66

77
[python]
88
with-pypy = false
99
with-legacy-python = true
1010
with-docs = true
1111
with-sphinx-doctests = true
1212
with-windows = true
13-
with-future-python = false
13+
with-future-python = true
1414

1515
[tox]
1616
use-flake8 = true
@@ -60,7 +60,7 @@ coverage-setenv = [
6060
]
6161

6262
[coverage]
63-
fail-under = 99.2
63+
fail-under = 98.9
6464

6565
[manifest]
6666
additional-rules = [

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Changes
66

77
- Document that ``__name__`` is needed to define classes.
88

9+
- Allow to use the package with Python 3.10 -- Caution: No security audit has
10+
been done so far.
11+
912

1013
5.1 (2020-10-07)
1114
----------------

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def read(*rnames):
5454
'Programming Language :: Python :: 3.7',
5555
'Programming Language :: Python :: 3.8',
5656
'Programming Language :: Python :: 3.9',
57+
'Programming Language :: Python :: 3.10',
5758
'Programming Language :: Python :: Implementation :: CPython',
5859
'Topic :: Security',
5960
],
@@ -69,7 +70,7 @@ def read(*rnames):
6970
package_dir={'': 'src'},
7071
install_requires=[
7172
],
72-
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.10", # NOQA: E501
73+
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.11", # NOQA: E501
7374
tests_require=tests_require,
7475
extras_require={
7576
'test': tests_require,

src/RestrictedPython/_compat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
IS_PY36_OR_GREATER = _version.major == 3 and _version.minor >= 6
1111
IS_PY37_OR_GREATER = _version.major == 3 and _version.minor >= 7
1212
IS_PY38_OR_GREATER = _version.major == 3 and _version.minor >= 8
13+
IS_PY310_OR_GREATER = _version.major == 3 and _version.minor >= 10
1314

1415
if IS_PY2: # pragma: PY2
1516
basestring = basestring # NOQA: F821 # Python 2 only built-in function

tests/test_compile.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from RestrictedPython._compat import IS_PY2
77
from RestrictedPython._compat import IS_PY3
88
from RestrictedPython._compat import IS_PY38_OR_GREATER
9+
from RestrictedPython._compat import IS_PY310_OR_GREATER
910
from tests.helper import restricted_eval
1011

1112
import platform
@@ -40,7 +41,9 @@ def test_compile__compile_restricted_invalid_mode_input():
4041
def test_compile__invalid_syntax():
4142
with pytest.raises(SyntaxError) as err:
4243
compile_restricted(INVALID_ASSINGMENT, '<string>', 'exec')
43-
if IS_PY38_OR_GREATER:
44+
if IS_PY310_OR_GREATER:
45+
assert "SyntaxError: cannot assign to literal here." in str(err.value)
46+
elif IS_PY38_OR_GREATER:
4447
assert "cannot assign to literal at statement:" in str(err.value)
4548
else:
4649
assert "can't assign to literal at statement:" in str(err.value)
@@ -120,9 +123,15 @@ def no_exec():
120123
def test_compile__compile_restricted_exec__10(): # pragma: PY3
121124
"""It is a SyntaxError to use the `exec` statement. (Python 3 only)"""
122125
result = compile_restricted_exec(EXEC_STATEMENT)
123-
assert (
124-
'Line 2: SyntaxError: Missing parentheses in call to \'exec\' at '
125-
'statement: "exec \'q = 1\'"',) == result.errors
126+
if IS_PY310_OR_GREATER:
127+
assert (
128+
'Line 2: SyntaxError: Missing parentheses in call to \'exec\'. Did'
129+
' you mean exec(...)? at statement: "exec \'q = 1\'"',
130+
) == result.errors
131+
else:
132+
assert (
133+
'Line 2: SyntaxError: Missing parentheses in call to \'exec\' at'
134+
' statement: "exec \'q = 1\'"',) == result.errors
126135

127136

128137
FUNCTION_DEF = """\

tests/test_compile_restricted_function.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from RestrictedPython import PrintCollector
33
from RestrictedPython import safe_builtins
44
from RestrictedPython._compat import IS_PY38_OR_GREATER
5+
from RestrictedPython._compat import IS_PY310_OR_GREATER
56
from types import FunctionType
67

78

@@ -210,9 +211,15 @@ def test_compile_restricted_function_handle_SyntaxError():
210211
)
211212

212213
assert result.code is None
213-
assert result.errors == (
214-
"Line 1: SyntaxError: unexpected EOF while parsing at statement: 'a('",
215-
)
214+
if IS_PY310_OR_GREATER:
215+
assert result.errors == (
216+
"Line 1: SyntaxError: '(' was never closed at statement: 'a('",
217+
)
218+
else:
219+
assert result.errors == (
220+
"Line 1: SyntaxError: unexpected EOF while parsing at statement:"
221+
" 'a('",
222+
)
216223

217224

218225
def test_compile_restricted_function_invalid_syntax():
@@ -230,7 +237,11 @@ def test_compile_restricted_function_invalid_syntax():
230237
assert len(result.errors) == 1
231238
error_msg = result.errors[0]
232239

233-
if IS_PY38_OR_GREATER:
240+
if IS_PY310_OR_GREATER:
241+
assert error_msg.startswith(
242+
"Line 1: SyntaxError: cannot assign to literal here. Maybe "
243+
)
244+
elif IS_PY38_OR_GREATER:
234245
assert error_msg.startswith(
235246
"Line 1: SyntaxError: cannot assign to literal at statement:"
236247
)

tox.ini

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ envlist =
1010
py37
1111
py38
1212
py39
13+
py310
1314
docs
1415
coverage
1516
py38-datetime
@@ -22,8 +23,6 @@ deps =
2223
-cconstraints.txt
2324
pytest-cov
2425
coverage-python-version
25-
# Until repoze.sphinx.autointerface supports Sphinx 4.x we cannot use it:
26-
Sphinx < 4
2726
setenv =
2827
COVERAGE_FILE=.coverage.{envname}
2928
commands =
@@ -61,6 +60,7 @@ deps =
6160
flake8
6261
check-manifest
6362
check-python-versions
63+
wheel
6464
commands =
6565
flake8 src setup.py
6666
check-manifest
@@ -69,8 +69,6 @@ commands =
6969
[testenv:docs]
7070
basepython = python3
7171
skip_install = false
72-
# Until repoze.sphinx.autointerface supports Sphinx 4.x we cannot use it:
73-
deps = Sphinx < 4
7472
commands_pre =
7573
commands =
7674
sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html
@@ -83,8 +81,6 @@ allowlist_externals =
8381
deps =
8482
coverage
8583
coverage-python-version
86-
# Until repoze.sphinx.autointerface supports Sphinx 4.x we cannot use it:
87-
Sphinx < 4
8884
datetime: DateTime
8985
-cconstraints.txt
9086
pytest-cov
@@ -96,7 +92,7 @@ commands =
9692
pytest --cov=src --cov=tests --cov-report= {posargs}
9793
coverage run -a -m sphinx -b doctest -d {envdir}/.cache/doctrees docs {envdir}/.cache/doctest
9894
coverage html
99-
coverage report -m --fail-under=99.2
95+
coverage report -m --fail-under=98.9
10096

10197
[coverage:run]
10298
branch = True

0 commit comments

Comments
 (0)