Skip to content
Myr

Make slice work with async generators

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

authored by Armin Ronacher · committed by Armin Ronacher · parent 2b03052 · Browse files · 2 files+15 added−0 removed
This commit

State

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

Diff stats

2 files+15 added−0 removed

  • tests:+9 added−0 removed
  • other:+6 added−0 removed

2 files+15 added−0 removed

modified:jinja2/asyncfilters.py+6 added
120 unmodified lines
121 rv += func(item)122 return rv123124125@asyncfiltervariant(filters.do_slice)126async def do_slice(value, slices, fill_with=None):127 return filters.do_slice(await auto_to_seq(value), slices, fill_with)128129130ASYNC_FILTERS = {131 'first': do_first,132 'groupby': do_groupby,133 'join': do_join,
5 unmodified lines
139 'map': do_map,140 'select': do_select,141 'selectattr': do_selectattr,142 'sum': do_sum,143 'slice': do_slice,144}
modified:tests/test_asyncfilters.py+9 added
214 unmodified lines
215 'foo': 23,216 'bar': 1,217 'baz': 18,218 }) == '42'219220221@mark_dualiter('items', lambda: range(10))222def test_slice(env_async, items):223 tmpl = env_async.from_string('{{ items()|slice(3)|list }}|'224 '{{ items()|slice(3, "X")|list }}')225 out = tmpl.render(items=items)226 assert out == ("[[0, 1, 2, 3], [4, 5, 6], [7, 8, 9]]|"227 "[[0, 1, 2, 3], [4, 5, 6, 'X'], [7, 8, 9, 'X']]")