Skip to content
Myr

Merge pull request #922 from CleoQc/feature/support_scientific_notation

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

Feature/support scientific notation

authored by David Lord · committed by GitHub · parents 626bdd0, 483b62e · Browse files · 5 files+46 added−12 removed
This commit

State

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

Diff stats

5 files+46 added−12 removed

  • tests:+33 added−4 removed
  • other:+13 added−8 removed

5 files+46 added−12 removed

modified:docs/templates.rst+8 added-6 removed
394 unmodified lines
395this template, it first locates the parent. The extends tag should be the396first tag in the template. Everything before it is printed out normally and397may cause confusion. For details about this behavior and how to take398advantage of it, see :ref:`null-master-fallback`. Also a block will always be399filled in regardless of whether the surrounding condition is evaluated to be true 399filled in regardless of whether the surrounding condition is evaluated to be true400or false.401402The filename of the template depends on the template loader. For example, the403:class:`FileSystemLoader` allows you to access other templates by giving the
772 unmodified lines
1176 useful whenever you need a string in the template (e.g. as1177 arguments to function calls and filters, or just to extend or include a1178 template).1179118042 / 42.23:1181 Integers and floating point numbers are created by just writing the1182 number down. If a dot is present, the number is a float, otherwise an1183 integer. Keep in mind that, in Python, ``42`` and ``42.0``1184 are different (``int`` and ``float``, respectively).118042:1181 Integers are whole numbers without a decimal part.1182118342.23 / 42.1e2:1184 Floating point numbers can be written using a '.' as a decimal mark.1185 They can also be written in scientific notation with an upper or1186 lower case 'e' to indicate the exponent part.11871188['list', 'of', 'objects']:1189 Everything between two brackets is a list. Lists are useful for storing1190 sequential data to be iterated over. For example, you can easily1191 create a list of links using lists and tuples for (and with) a for loop::
568 unmodified lines
modified:jinja2/lexer.py+3 added-2 removed
13 unmodified lines
14 :copyright: (c) 2017 by the Jinja Team.15 :license: BSD, see LICENSE for more details.16"""17import re18from ast import literal_eval19from collections import deque20from operator import itemgetter2122from jinja2._compat import implements_iterator, intern, iteritems, text_type
29 unmodified lines
52 import jinja253 del jinja2._identifier54 del _identifier5555float_re = re.compile(r'(?<!\.)\d+\.\d+')56float_re = re.compile(r'(?<!\.)\d+(?:\.\d+)?(?:e[+\-]?\d+)?', re.IGNORECASE)57newline_re = re.compile(r'(\r\n|\r|\n)')5859# internal the tokens and keep references to them60TOKEN_ADD = intern('add')
540 unmodified lines
601 raise TemplateSyntaxError(msg, lineno, name, filename)602 elif token == 'integer':603 value = int(value)604 elif token == 'float':604 value = float(value)605 value = literal_eval(value)606 elif token == 'operator':607 token = operators[value]608 yield Token(lineno, token, value)609
141 unmodified lines
modified:tests/test_filters.py+3 added-1 removed
134 unmodified lines
135136 def test_float(self, env):137 tmpl = env.from_string('{{ "42"|float }}|'138 '{{ "ajsghasjgd"|float }}|'139 '{{ "10e1"|float }}|'140 '{{ "10.5e-10"|float }}|'141 '{{ "32.32"|float }}')142 out = tmpl.render()141 assert out == '42.0|0.0|32.32'143 assert out == '42.0|0.0|100.0|1.05e-09|32.32'144145 def test_format(self, env):146 tmpl = env.from_string('''{{ "%s|%s"|format("a", "b") }}''')147 out = tmpl.render()
577 unmodified lines
modified:tests/test_lexnparse.py+30 added-3 removed
334 unmodified lines
335 def test_inop(self, env):336 tmpl = env.from_string('{{ 1 in [1, 2, 3] }}|{{ 1 not in [1, 2, 3] }}')337 assert tmpl.render() == 'True|False'338339 def test_literals(self, env):340 tmpl = env.from_string('{{ [] }}|{{ {} }}|{{ () }}')341 assert tmpl.render().lower() == '[]|{}|()'339 @pytest.mark.parametrize("value", ("[]", "{}", "()"))340 def test_collection_literal(self, env, value):341 t = env.from_string("{{ %s }}" % value)342 assert t.render() == value343344 @pytest.mark.parametrize("value", ("1", "123"))345 def test_int_literal(self, env, value):346 t = env.from_string("{{ %s }}" % value)347 assert t.render() == value348349 @pytest.mark.parametrize(350 "value",351 (352 "1.2",353 "34.56",354 ("1e0", "1.0"),355 ("10e1", "100.0"),356 ("2.5e100", "2.5e+100"),357 "2.5e+100",358 ("25.6e-10", "2.56e-09"),359 ),360 )361 def test_float_literal(self, env, value):362 if isinstance(value, tuple):363 value, expect = value364 else:365 expect = value366367 t = env.from_string("{{ %s }}" % value)368 assert t.render() == expect369370 def test_bool(self, env):371 tmpl = env.from_string('{{ true and false }}|{{ false '372 'or true }}|{{ not false }}')373 assert tmpl.render() == 'False|True|True'
319 unmodified lines
modified:CHANGES.rst+2 added
19 unmodified lines
20 ``lstrip_blocks == False`` (`#748`_)21- Added a ``default`` parameter for the ``map`` filter. (`#557`_)22- Exclude environment globals from23 :func:`meta.find_undeclared_variables`. #93124- Float literals can be written with scientific notation, like25 ``{{ 2.56e-3 }}``. #912, #9222627.. _#557: https://github.com/pallets/jinja/issues/55728.. _#765: https://github.com/pallets/jinja/issues/76529.. _#748: https://github.com/pallets/jinja/issues/748
613 unmodified lines