:pr:`1960`
- The runtime uses the correct ``concat`` function for the current environment
when calling block references. :issue:`1701`
+- Make ``|unique`` async-aware, allowing it to be used after another
+ async-aware filter. :issue:`1781`
Version 3.1.4
@pass_environment
-def do_unique(
+def sync_do_unique(
environment: "Environment",
value: "t.Iterable[V]",
case_sensitive: bool = False,
yield item
+@async_variant(sync_do_unique) # type: ignore
+async def do_unique(
+ environment: "Environment",
+ value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",
+ case_sensitive: bool = False,
+ attribute: t.Optional[t.Union[str, int]] = None,
+) -> "t.Iterator[V]":
+ return sync_do_unique(
+ environment, await auto_to_list(value), case_sensitive, attribute
+ )
+
+
def _min_or_max(
environment: "Environment",
value: "t.Iterable[V]",
)
+def test_unique_with_async_gen(env_async):
+ items = ["a", "b", "c", "c", "a", "d", "z"]
+ tmpl = env_async.from_string("{{ items|reject('==', 'z')|unique|list }}")
+ out = tmpl.render(items=items)
+ assert out == "['a', 'b', 'c', 'd']"
+
+
def test_custom_async_filter(env_async, run_async_fn):
async def customfilter(val):
return str(val)