Skip to content
Myr

Clarify that last filter doesn't work with generators

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

authored by PinkFloyded · committed by PinkFloyded · parent c89351f · Browse files · 1 file+9 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

1 file+9 added−1 removed

  • other:+9 added−1 removed

1 file+9 added−1 removed

modified:jinja2/filters.py+9 added-1 removed
438 unmodified lines
439440441@environmentfilter442def do_last(environment, seq):443 """Return the last item of a sequence."""443 """444 Return the last item of a sequence.445446 Note: Does not work with generators. You may want to explicitly convert it to a list:447448 .. sourcecode:: jinja449450 {{ data | selectattr('name', '==', 'Jinja') | list | last }}451 """452 try:453 return next(iter(reversed(seq)))454 except StopIteration:455 return environment.undefined('No last item, sequence was empty.')
749 unmodified lines