Merge pull request #1534 from pallets/drop-python-3.6
Before adoption: this commit came in with the history the project adopted, so no landing records it.
drop Python 3.6
authored by David Lord · committed by GitHub · parents 5e2385c, 5308c95 · Browse files · 11 files·+27 added−157 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+27 added−157 removed
- tests:+14 added−44 removed
- other:+13 added−113 removed
Provenance
- Commit
b2bc7be- Tree
b609b32- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
5e2385c- Parent 2
5308c95
11 files changed+27 added−157 removed
modified:.github/workflows/tests.yaml-1 removed
29 unmodified lines30313233343435363724 unmodified lines29 unmodified lines - {name: '3.11-dev', python: '3.11-dev', os: ubuntu-latest, tox: py311} - {name: '3.9', python: '3.9', os: ubuntu-latest, tox: py39} - {name: '3.8', python: '3.8', os: ubuntu-latest, tox: py38} - {name: '3.7', python: '3.7', os: ubuntu-latest, tox: py37} - {name: '3.6', python: '3.6', os: ubuntu-latest, tox: py36} - {name: 'PyPy', python: 'pypy-3.7', os: ubuntu-latest, tox: pypy37} - {name: Typing, python: '3.10', os: ubuntu-latest, tox: typing} steps: - uses: actions/checkout@v224 unmodified linesmodified:docs/faq.rst-20 removed
123 unmodified lines124 instead that one can assign to a variable by using set::125 126 {% set comments = get_latest_comments() %}127 128-My tracebacks look weird. What's happening?129--------------------------------------------128 131-Jinja can rewrite tracebacks so they show the template lines numbers and132-source rather than the underlying compiled code, but this requires133-special Python support. CPython <3.7 requires ``ctypes``, and PyPy134-requires transparent proxy support.135-136-If you are using Google App Engine, ``ctypes`` is not available. You can137-make it available in development, but not in production.138-139-.. code-block:: python140-141- import os142- if os.environ.get('SERVER_SOFTWARE', '').startswith('Dev'):143- from google.appengine.tools.devappserver2.python import sandbox144- sandbox._WHITE_LIST_C_MODULES += ['_ctypes', 'gestalt']145-146-Credit for this snippet goes to `Thomas Johansson147-<https://stackoverflow.com/questions/3086091/debug-jinja2-in-google-app-engine/3694434#3694434>`_148-129 My Macros are overridden by something130 -------------------------------------131 132 In some situations the Jinja scoping appears arbitrary:23 unmodified linesmodified:docs/intro.rst+1 added-1 removed
28 unmodified lines29 Installation30 ------------31 32 We recommend using the latest version of Python. Jinja supports Python33-3.6 and newer. We also recommend using a `virtual environment`_ in order33+3.7 and newer. We also recommend using a `virtual environment`_ in order34 to isolate your project dependencies from other projects and the system.35 36 .. _virtual environment: https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments37 26 unmodified linesmodified:src/jinja2/compiler.py-1 removed
833 unmodified lines834 exported_names = sorted(exported + async_exported)835 else:836 exported_names = sorted(exported)837 838- self.writeline("from __future__ import generator_stop") # Python < 3.7838 self.writeline("from jinja2.runtime import " + ", ".join(exported_names))839 840 # if we want a deferred initialization we cannot move the841 # environment into a local name1115 unmodified linesmodified:src/jinja2/debug.py+2 added-70 removed
1-import platform1 import sys2 import typing as t3 from types import CodeType4 from types import TracebackType61 unmodified lines66 tb_next = None67 68 # Assign tb_next in reverse to avoid circular references.69 for tb in reversed(stack):71- tb_next = tb_set_next(tb, tb_next)70+ tb.tb_next = tb_next71+ tb_next = tb72 73 return exc_value.with_traceback(tb_next)74 75 132 unmodified lines208 else:209 data[name] = value210 211 return data212-213-214-if sys.version_info >= (3, 7):215- # tb_next is directly assignable as of Python 3.7216- def tb_set_next(217- tb: TracebackType, tb_next: t.Optional[TracebackType]218- ) -> TracebackType:219- tb.tb_next = tb_next220- return tb221-222-223-elif platform.python_implementation() == "PyPy":224- # PyPy might have special support, and won't work with ctypes.225- try:226- import tputil # type: ignore227- except ImportError:228- # Without tproxy support, use the original traceback.229- def tb_set_next(230- tb: TracebackType, tb_next: t.Optional[TracebackType]231- ) -> TracebackType:232- return tb233-234- else:235- # With tproxy support, create a proxy around the traceback that236- # returns the new tb_next.237- def tb_set_next(238- tb: TracebackType, tb_next: t.Optional[TracebackType]239- ) -> TracebackType:240- def controller(op): # type: ignore241- if op.opname == "__getattribute__" and op.args[0] == "tb_next":242- return tb_next243-244- return op.delegate()245-246- return tputil.make_proxy(controller, obj=tb) # type: ignore247-248-249-else:250- # Use ctypes to assign tb_next at the C level since it's read-only251- # from Python.252- import ctypes253-254- class _CTraceback(ctypes.Structure):255- _fields_ = [256- # Extra PyObject slots when compiled with Py_TRACE_REFS.257- ("PyObject_HEAD", ctypes.c_byte * object().__sizeof__()),258- # Only care about tb_next as an object, not a traceback.259- ("tb_next", ctypes.py_object),260- ]261-262- def tb_set_next(263- tb: TracebackType, tb_next: t.Optional[TracebackType]264- ) -> TracebackType:265- c_tb = _CTraceback.from_address(id(tb))266-267- # Clear out the old tb_next.268- if tb.tb_next is not None:269- c_tb_next = ctypes.py_object(tb.tb_next)270- c_tb.tb_next = ctypes.py_object()271- ctypes.pythonapi.Py_DecRef(c_tb_next)272-273- # Assign the new tb_next.274- if tb_next is not None:275- c_tb_next = ctypes.py_object(tb_next)276- ctypes.pythonapi.Py_IncRef(c_tb_next)277- c_tb.tb_next = c_tb_next278-279- return tbmodified:src/jinja2/environment.py+6 added-16 removed
1 """Classes for managing templates and their runtime and compile time2 options.3 """4 import os5-import sys5 import typing6 import typing as t7 import weakref8 from collections import ChainMap1270 unmodified lines1279 import asyncio1280 1281 close = False1282 1284- if sys.version_info < (3, 7):1285- loop = asyncio.get_event_loop()1286- else:1287- try:1288- loop = asyncio.get_running_loop()1289- except RuntimeError:1290- loop = asyncio.new_event_loop()1291- close = True1283+ try:1284+ loop = asyncio.get_running_loop()1285+ except RuntimeError:1286+ loop = asyncio.new_event_loop()1287+ close = True1288 1289 try:1290 return loop.run_until_complete(self.render_async(*args, **kwargs))1291 finally:47 unmodified lines1339 1340 async def to_list() -> t.List[str]:1341 return [x async for x in self.generate_async(*args, **kwargs)]1342 1347- if sys.version_info < (3, 7):1348- loop = asyncio.get_event_loop()1349- out = loop.run_until_complete(to_list())1350- else:1351- out = asyncio.run(to_list())1343+ yield from asyncio.run(to_list())1352-1353- yield from out1344 return1345 1346 ctx = self.new_context(dict(*args, **kwargs))1347 317 unmodified linesmodified:tests/test_async.py+14 added-30 removed
1 import asyncio2-import sys2 3 import pytest4 5 from jinja2 import ChainableUndefined6 unmodified lines12 from jinja2.exceptions import UndefinedError13 from jinja2.nativetypes import NativeEnvironment14 15 17-if sys.version_info < (3, 7):18-19- def run(coro):20- loop = asyncio.get_event_loop()21- return loop.run_until_complete(coro)22-23-24-else:25-26- def run(coro):27- return asyncio.run(coro)28-29-16 def test_basic_async():17 t = Template(18 "{% for item in [1, 2, 3] %}[{{ item }}]{% endfor %}", enable_async=True19 )20 21 async def func():22 return await t.render_async()23 38- rv = run(func())24+ rv = asyncio.run(func())25 assert rv == "[1][2][3]"26 27 28 def test_await_on_calls():7 unmodified lines36 37 async def func():38 return await t.render_async(async_func=async_func, normal_func=normal_func)39 54- rv = run(func())40+ rv = asyncio.run(func())41 assert rv == "65"42 43 44 def test_await_on_calls_normal_render():5 unmodified lines50 def normal_func():51 return 2352 53 rv = t.render(async_func=async_func, normal_func=normal_func)68-54 assert rv == "65"55 56 57 def test_await_and_macros():7 unmodified lines65 66 async def func():67 return await t.render_async(async_func=async_func)68 84- rv = run(func())69+ rv = asyncio.run(func())70 assert rv == "[42][42]"71 72 73 def test_async_blocks():5 unmodified lines79 80 async def func():81 return await t.render_async()82 98- rv = run(func())83+ rv = asyncio.run(func())84 assert rv == "<Test><Test>"85 86 87 def test_async_generate():68 unmodified lines156 test_env_async.from_string('{% from "foo" import bar, with, context %}')157 test_env_async.from_string('{% from "foo" import bar, with with context %}')158 159 def test_exports(self, test_env_async):175- m = run(176- test_env_async.from_string(177- """160+ coro = test_env_async.from_string(161+ """162 {% macro toplevel() %}...{% endmacro %}163 {% macro __private() %}...{% endmacro %}164 {% set variable = 42 %}165 {% for item in [1] %}166 {% macro notthere() %}{% endmacro %}167 {% endfor %}184- """185- )._get_default_module_async()186- )187- assert run(m.toplevel()) == "..."168+ """169+ )._get_default_module_async()170+ m = asyncio.run(coro)171+ assert asyncio.run(m.toplevel()) == "..."172 assert not hasattr(m, "__missing")173 assert m.variable == 42174 assert not hasattr(m, "notthere")175 428 unmodified lines604 )605 actual = await t.render_async()606 assert actual == "Bar"607 624- run(_test())608+ asyncio.run(_test())609 610 611 def test_chainable_undefined_aiter():612 async def _test():4 unmodified lines617 )618 rv = await t.render_async(a={})619 assert rv == ""620 637- run(_test())621+ asyncio.run(_test())622 623 624 @pytest.fixture625 def async_native_env():5 unmodified lines631 t = async_native_env.from_string("{{ x }}")632 rv = await t.render_async(x=23)633 assert rv == 23634 651- run(_test())635+ asyncio.run(_test())636 637 638 def test_native_list_async(async_native_env):639 async def _test():640 t = async_native_env.from_string("{{ x }}")641 rv = await t.render_async(x=list(range(3)))642 assert rv == [0, 1, 2]643 660- run(_test())644+ asyncio.run(_test())deleted:tests/test_features.py-14 removed
1-import pytest2-3-from jinja2 import Template4-5-6-# Python < 3.77-def test_generator_stop():8- class X:9- def __getattr__(self, name):10- raise StopIteration()11-12- t = Template("a{{ bad.bar() }}b")13- with pytest.raises(RuntimeError):14- t.render(bad=X())modified:.pre-commit-config.yaml+1 added-1 removed
3 unmodified lines4 - repo: https://github.com/asottile/pyupgrade5 rev: v2.29.06 hooks:7 - id: pyupgrade8- args: ["--py36-plus"]8+ args: ["--py37-plus"]9 - repo: https://github.com/asottile/reorder_python_imports10 rev: v2.6.011 hooks:12 - id: reorder-python-imports16 unmodified linesmodified:setup.cfg+2 added-2 removed
31 unmodified lines32 [options]33 packages = find:34 package_dir = = src35 include_package_data = true36-python_requires = >= 3.636+python_requires = >= 3.737 # Dependencies are in setup.py for GitHub's dependency graph.38 39 [options.packages.find]40 where = src44 unmodified lines85 src/jinja2/__init__.py: F40186 87 [mypy]88 files = src/jinja289-python_version = 3.689+python_version = 3.790 disallow_subclassing_any = True91 disallow_untyped_calls = True92 disallow_untyped_defs = True93 disallow_incomplete_defs = True15 unmodified linesmodified:tox.ini+1 added-1 removed
1 [tox]2 envlist =3- py{311,310,39,38,37,36,py37}3+ py3{11,10,9,8,7},pypy3{8,7}4 style5 typing6 docs7 skip_missing_interpreters = true17 unmodified lines