Skip to content
Myr

Merge pull request #799 from mkrizek/native-concat-list

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

Allow to pass a list to native_concat

authored by David Lord · committed by GitHub · parents 1f60059, 08a6fae · Browse files · 2 files+10 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

2 files+10 added−1 removed

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

2 files+10 added−1 removed

modified:jinja2/nativetypes.py+4 added-1 removed
1import sys2import types3from ast import literal_eval4from itertools import islice, chain5from jinja2 import nodes6from jinja2._compat import text_type
16 unmodified lines
2324 if len(head) == 1:25 out = head[0]26 else:27 if isinstance(nodes, types.GeneratorType):28 nodes = chain(head, nodes)26 out = u''.join([text_type(v) for v in chain(head, nodes)])29 out = u''.join([text_type(v) for v in nodes])3031 try:32 return literal_eval(out)33 except (ValueError, SyntaxError, MemoryError):
190 unmodified lines
modified:tests/test_nativetypes.py+6 added
106 unmodified lines
107 t = env.from_string("{{ true.__class__|string }}")108 result = t.render()109 assert not isinstance(result, type)110 assert result in ["<type 'bool'>", "<class 'bool'>"]111112 def test_string(self, env):113 t = env.from_string("[{{ 'all' }}]")114 result = t.render()115 assert isinstance(result, text_type)116 assert result == "[all]"