Skip to content
Myr

make unique filter async aware (#1782)

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

authored by David Lord · committed by GitHub · parents a4abbfd, 76af711 · Browse files · 3 files+22 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+22 added−1 removed

  • tests:+7 added−0 removed
  • other:+15 added−1 removed

3 files+22 added−1 removed

modified:src/jinja2/filters.py+13 added-1 removed
436 unmodified lines
437 return sorted(value, key=key_func, reverse=reverse)438439440@pass_environment441def do_unique(441def sync_do_unique(442 environment: "Environment",443 value: "t.Iterable[V]",444 case_sensitive: bool = False,445 attribute: t.Optional[t.Union[str, int]] = None,
23 unmodified lines
469 seen.add(key)470 yield item471472473@async_variant(sync_do_unique) # type: ignore474async def do_unique(475 environment: "Environment",476 value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",477 case_sensitive: bool = False,478 attribute: t.Optional[t.Union[str, int]] = None,479) -> "t.Iterator[V]":480 return sync_do_unique(481 environment, await auto_to_list(value), case_sensitive, attribute482 )483484485def _min_or_max(486 environment: "Environment",487 value: "t.Iterable[V]",488 func: "t.Callable[..., V]",
1390 unmodified lines
modified:tests/test_async_filters.py+7 added
275 unmodified lines
276 "[[0, 1, 2, 3], [4, 5, 6, 'X'], [7, 8, 9, 'X']]"277 )278279280def test_unique_with_async_gen(env_async):281 items = ["a", "b", "c", "c", "a", "d", "z"]282 tmpl = env_async.from_string("{{ items|reject('==', 'z')|unique|list }}")283 out = tmpl.render(items=items)284 assert out == "['a', 'b', 'c', 'd']"285286287def test_custom_async_filter(env_async, run_async_fn):288 async def customfilter(val):289 return str(val)290
31 unmodified lines
modified:CHANGES.rst+2 added
14 unmodified lines
15- Avoid leaving async generators unclosed in blocks, includes and extends.16 :pr:`1960`17- The runtime uses the correct ``concat`` function for the current environment18 when calling block references. :issue:`1701`19- Make ``|unique`` async-aware, allowing it to be used after another20 async-aware filter. :issue:`1781`212223Version 3.1.424-------------
994 unmodified lines