Skip to content
Myr

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

11 files+27 added−157 removed

modified:.github/workflows/tests.yaml-1 removed
modified:docs/faq.rst-20 removed
123 unmodified lines
124instead that one can assign to a variable by using set::125126 {% set comments = get_latest_comments() %}127128My tracebacks look weird. What's happening?129-------------------------------------------128131Jinja can rewrite tracebacks so they show the template lines numbers and132source rather than the underlying compiled code, but this requires133special Python support. CPython <3.7 requires ``ctypes``, and PyPy134requires transparent proxy support.135136If you are using Google App Engine, ``ctypes`` is not available. You can137make it available in development, but not in production.138139.. code-block:: python140141 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']145146Credit for this snippet goes to `Thomas Johansson147<https://stackoverflow.com/questions/3086091/debug-jinja2-in-google-app-engine/3694434#3694434>`_148129My Macros are overridden by something130-------------------------------------131132In some situations the Jinja scoping appears arbitrary:
23 unmodified lines
modified:docs/intro.rst+1 added-1 removed
28 unmodified lines
29Installation30------------3132We recommend using the latest version of Python. Jinja supports Python333.6 and newer. We also recommend using a `virtual environment`_ in order333.7 and newer. We also recommend using a `virtual environment`_ in order34to isolate your project dependencies from other projects and the system.3536.. _virtual environment: https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments37
26 unmodified lines
modified:src/jinja2/compiler.py-1 removed
833 unmodified lines
834 exported_names = sorted(exported + async_exported)835 else:836 exported_names = sorted(exported)837838 self.writeline("from __future__ import generator_stop") # Python < 3.7838 self.writeline("from jinja2.runtime import " + ", ".join(exported_names))839840 # if we want a deferred initialization we cannot move the841 # environment into a local name
1115 unmodified lines
modified:src/jinja2/debug.py+2 added-70 removed
1import platform1import sys2import typing as t3from types import CodeType4from types import TracebackType
61 unmodified lines
66 tb_next = None6768 # 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 = tb7273 return exc_value.with_traceback(tb_next)7475
132 unmodified lines
208 else:209 data[name] = value210211 return data212213214if 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 tb221222223elif 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 tb233234 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_next243244 return op.delegate()245246 return tputil.make_proxy(controller, obj=tb) # type: ignore247248249else:250 # Use ctypes to assign tb_next at the C level since it's read-only251 # from Python.252 import ctypes253254 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 ]261262 def tb_set_next(263 tb: TracebackType, tb_next: t.Optional[TracebackType]264 ) -> TracebackType:265 c_tb = _CTraceback.from_address(id(tb))266267 # 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)272273 # 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_next278279 return tb
modified:src/jinja2/environment.py+6 added-16 removed
1"""Classes for managing templates and their runtime and compile time2options.3"""4import os5import sys5import typing6import typing as t7import weakref8from collections import ChainMap
1270 unmodified lines
1279 import asyncio12801281 close = False12821284 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 = True12881289 try:1290 return loop.run_until_complete(self.render_async(*args, **kwargs))1291 finally:
47 unmodified lines
13391340 async def to_list() -> t.List[str]:1341 return [x async for x in self.generate_async(*args, **kwargs)]13421347 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())13521353 yield from out1344 return13451346 ctx = self.new_context(dict(*args, **kwargs))1347
317 unmodified lines
modified:tests/test_async.py+14 added-30 removed
1import asyncio2import sys23import pytest45from jinja2 import ChainableUndefined
6 unmodified lines
12from jinja2.exceptions import UndefinedError13from jinja2.nativetypes import NativeEnvironment141517if sys.version_info < (3, 7):1819 def run(coro):20 loop = asyncio.get_event_loop()21 return loop.run_until_complete(coro)222324else:2526 def run(coro):27 return asyncio.run(coro)282916def test_basic_async():17 t = Template(18 "{% for item in [1, 2, 3] %}[{{ item }}]{% endfor %}", enable_async=True19 )2021 async def func():22 return await t.render_async()2338 rv = run(func())24 rv = asyncio.run(func())25 assert rv == "[1][2][3]"262728def test_await_on_calls():
7 unmodified lines
3637 async def func():38 return await t.render_async(async_func=async_func, normal_func=normal_func)3954 rv = run(func())40 rv = asyncio.run(func())41 assert rv == "65"424344def test_await_on_calls_normal_render():
5 unmodified lines
50 def normal_func():51 return 235253 rv = t.render(async_func=async_func, normal_func=normal_func)6854 assert rv == "65"555657def test_await_and_macros():
7 unmodified lines
6566 async def func():67 return await t.render_async(async_func=async_func)6884 rv = run(func())69 rv = asyncio.run(func())70 assert rv == "[42][42]"717273def test_async_blocks():
5 unmodified lines
7980 async def func():81 return await t.render_async()8298 rv = run(func())83 rv = asyncio.run(func())84 assert rv == "<Test><Test>"858687def test_async_generate():
68 unmodified lines
156 test_env_async.from_string('{% from "foo" import bar, with, context %}')157 test_env_async.from_string('{% from "foo" import bar, with with context %}')158159 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 lines
604 )605 actual = await t.render_async()606 assert actual == "Bar"607624 run(_test())608 asyncio.run(_test())609610611def test_chainable_undefined_aiter():612 async def _test():
4 unmodified lines
617 )618 rv = await t.render_async(a={})619 assert rv == ""620637 run(_test())621 asyncio.run(_test())622623624@pytest.fixture625def async_native_env():
5 unmodified lines
631 t = async_native_env.from_string("{{ x }}")632 rv = await t.render_async(x=23)633 assert rv == 23634651 run(_test())635 asyncio.run(_test())636637638def 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]643660 run(_test())644 asyncio.run(_test())
deleted:tests/test_features.py-14 removed
1import pytest23from jinja2 import Template456# Python < 3.77def test_generator_stop():8 class X:9 def __getattr__(self, name):10 raise StopIteration()1112 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 lines
4 - 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-imports
16 unmodified lines
modified:setup.cfg+2 added-2 removed
31 unmodified lines
32[options]33packages = find:34package_dir = = src35include_package_data = true36python_requires = >= 3.636python_requires = >= 3.737# Dependencies are in setup.py for GitHub's dependency graph.3839[options.packages.find]40where = src
44 unmodified lines
85 src/jinja2/__init__.py: F4018687[mypy]88files = src/jinja289python_version = 3.689python_version = 3.790disallow_subclassing_any = True91disallow_untyped_calls = True92disallow_untyped_defs = True93disallow_incomplete_defs = True
15 unmodified lines
modified:tox.ini+1 added-1 removed
1[tox]2envlist =3 py{311,310,39,38,37,36,py37}3 py3{11,10,9,8,7},pypy3{8,7}4 style5 typing6 docs7skip_missing_interpreters = true
17 unmodified lines