Skip to content
Myr

Merge pull request #1181 from bartfeenstra/async-namespace

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Allow namespaces to be used in asynchronously rendered templates.

authored by David Lord · committed by GitHub · parents 5f95471, 0fd45a4 · Browse files · 3 files+15 added−1 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+15 added−1 removed

  • tests:+11 added−0 removed
  • other:+4 added−1 removed

3 files+15 added−1 removed

modified:src/jinja2/utils.py+2 added-1 removed
695 unmodified lines
696 self, args = args[0], args[1:]697 self.__attrs = dict(*args, **kwargs)698699 def __getattribute__(self, name):700 if name == "_Namespace__attrs":700 # __class__ is needed for the awaitable check in async mode701 if name in {"_Namespace__attrs", "__class__"}:702 return object.__getattribute__(self, name)703 try:704 return self.__attrs[name]705 except KeyError:
27 unmodified lines
modified:tests/test_async.py+11 added
576 unmodified lines
577578 def test_awaitable_property_slicing(self, test_env_async):579 t = test_env_async.from_string("{% for x in a.b[:1] %}{{ x }}{% endfor %}")580 assert t.render(a=dict(b=[1, 2, 3])) == "1"581582583def test_namespace_awaitable(test_env_async):584 async def _test():585 t = test_env_async.from_string(586 '{% set ns = namespace(foo="Bar") %}{{ ns.foo }}'587 )588 actual = await t.render_async()589 assert actual == "Bar"590591 run(_test())
modified:CHANGES.rst+2 added
21 unmodified lines
22 :pep:`451` simultaneously, the changes are reverted until 3.0.23 :pr:`1182`24- Fix line numbers in error messages when newlines are stripped.25 :pr:`1178`26- The special ``namespace()`` assignment object in templates works in27 async environments. :issue:`1180`282930Version 2.11.131--------------
737 unmodified lines