From 785485114f8b008572bd863eb93e43de5386a15f Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Thu, 12 Jan 2017 15:53:09 +0100 Subject: [PATCH] Restore original tuple repr for grouper. Fixes #654 --- CHANGES | 7 +++++++ jinja2/filters.py | 6 ++++++ tests/test_regression.py | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/CHANGES b/CHANGES index f95f41a4..ed9bd0ea 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,13 @@ Jinja2 Changelog ================ +Version 2.9.5 +------------- +(bugfix release, no release date yet) + +- Restored the original repr of the internal `_GroupTuple` because this + caused issues with ansible and it was an unintended change. (#654) + Version 2.9.4 ------------- (bugfix release, released on January 10th 2017) diff --git a/jinja2/filters.py b/jinja2/filters.py index f4cd7968..d3726b3b 100644 --- a/jinja2/filters.py +++ b/jinja2/filters.py @@ -688,7 +688,13 @@ def do_round(value, precision=0, method='common'): return func(value * (10 ** precision)) / (10 ** precision) +# Use a regular tuple repr here. This is what we did in the past and we +# really want to hide this custom type as much as possible. In particular +# we do not want to accidentally expose an auto generated repr in case +# people start to print this out in comments or something similar for +# debugging. _GroupTuple = namedtuple('_GroupTuple', ['grouper', 'list']) +_GroupTuple.__repr__ = tuple.__repr__ @environmentfilter def do_groupby(environment, value, attribute): diff --git a/tests/test_regression.py b/tests/test_regression.py index dbed823f..fdb78efb 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -497,3 +497,10 @@ class TestBug(object): 'main': '{% for item in [1, 2, 3] %}{% include "inc" %}{% endfor %}', })) assert env.get_template('main').render() == '123' + + def test_grouper_repr(self): + from jinja2.filters import _GroupTuple + t = _GroupTuple('foo', [1, 2]) + assert t.grouper == 'foo' + assert t.list == [1, 2] + assert repr(t) == "('foo', [1, 2])" -- 2.47.2