From: Tim Bray Date: Thu, 10 Jul 2014 10:43:53 +0000 (+0100) Subject: decimal is a number X-Git-Tag: 2.8~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdeaa33d0f049641b2b0af108593449842a8d238;p=thirdparty%2Fjinja.git decimal is a number --- diff --git a/CHANGES b/CHANGES index eaa6e6bf..cb5e7848 100644 --- a/CHANGES +++ b/CHANGES @@ -21,6 +21,7 @@ Version 2.8 - Implemented a block ``set`` tag. - Default cache size was incrased to 400 from a low 50. - Fixed ``is number`` test to accept long integers in all Python versions. +- Changed ``is number`` to accept Decimal as a number. - Added a check for default arguments followed by non-default arguments. This change makes ``{% macro m(x, y=1, z) %}...{% endmacro %}`` a syntax error. The previous behavior for this code was broken anyway (resulting in the default diff --git a/jinja2/tests.py b/jinja2/tests.py index 9420239d..b88d4c36 100644 --- a/jinja2/tests.py +++ b/jinja2/tests.py @@ -12,7 +12,7 @@ import re from collections import Mapping from jinja2.runtime import Undefined from jinja2._compat import text_type, string_types, integer_types - +import decimal number_re = re.compile(r'^-?\d+(\.\d+)?$') regex_type = type(number_re) @@ -88,7 +88,7 @@ def test_mapping(value): def test_number(value): """Return true if the variable is a number.""" - return isinstance(value, integer_types + (float, complex)) + return isinstance(value, integer_types + (float, complex, decimal.Decimal)) def test_sequence(value):