add parens around auto_await for filters and calls
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent a819eb3 · Browse files · 3 files·+22 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+22 added−4 removed
- tests:+16 added−0 removed
- other:+6 added−4 removed
Provenance
- Commit
a150ff7- Tree
abce210- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
a819eb3
3 files changed+22 added−4 removed
modified:src/jinja2/compiler.py+4 added-4 removed
1753 unmodified lines1754 def _filter_test_common(1755 self, node: t.Union[nodes.Filter, nodes.Test], frame: Frame, is_filter: bool1756 ) -> t.Iterator[None]:1757 if self.environment.is_async:1758- self.write("await auto_await(")1758+ self.write("(await auto_await(")1759 1760 if is_filter:1761 self.write(f"{self.filters[node.name]}(")1762 func = self.environment.filters.get(node.name)26 unmodified lines1789 self.signature(node, frame)1790 self.write(")")1791 1792 if self.environment.is_async:1793- self.write(")")1793+ self.write("))")1794 1795 @optimizeconst1796 def visit_Filter(self, node: nodes.Filter, frame: Frame) -> None:1797 with self._filter_test_common(node, frame, True):43 unmodified lines1841 def visit_Call(1842 self, node: nodes.Call, frame: Frame, forward_caller: bool = False1843 ) -> None:1844 if self.environment.is_async:1845- self.write("await auto_await(")1845+ self.write("(await auto_await(")1846 if self.environment.sandboxed:1847 self.write("environment.call(context, ")1848 else:1849 self.write("context.call(")7 unmodified lines1857 extra_kwargs = dict(loop_kwargs, **block_kwargs)1858 self.signature(node, frame, extra_kwargs)1859 self.write(")")1860 if self.environment.is_async:1861- self.write(")")1861+ self.write("))")1862 1863 def visit_Keyword(self, node: nodes.Keyword, frame: Frame) -> None:1864 self.write(node.key + "=")1865 self.visit(node.value, frame)92 unmodified linesmodified:tests/test_async.py+16 added
640 unmodified lines641 rv = await t.render_async(x=list(range(3)))642 assert rv == [0, 1, 2]643 644 asyncio.run(_test())645+646+647+def test_getitem_after_filter():648+ env = Environment(enable_async=True)649+ env.filters["add_each"] = lambda v, x: [i + x for i in v]650+ t = env.from_string("{{ (a|add_each(2))[1:] }}")651+ out = t.render(a=range(3))652+ assert out == "[3, 4]"653+654+655+def test_getitem_after_call():656+ env = Environment(enable_async=True)657+ env.globals["add_each"] = lambda v, x: [i + x for i in v]658+ t = env.from_string("{{ add_each(a, 2)[1:] }}")659+ out = t.render(a=range(3))660+ assert out == "[3, 4]"modified:CHANGES.rst+2 added
29 unmodified lines30 :pr:`1571`31 - Filters and tests decorated with ``@async_variant`` are pickleable.32 :pr:`1612`33 - Add ``items`` filter. :issue:`1561`34+- Subscriptions (``[0]``, etc.) can be used after filters, tests, and35+ calls when the environment is in async mode. :issue:`1573`36 37 38 Version 3.0.339 -------------911 unmodified lines