Mercurial > public > mercurial-scm > hg
comparison mercurial/templatefilters.py @ 31880:a0f2d83f8083
templater: remove __iter__() from _hybrid, resolve it explicitly
The goal is to fix "{hybrid_obj|json}" output.
A _hybrid object must act as a list or a dict as well as a generator of
legacy template strings. Before, _hybrid.__iter__() was assigned for legacy
template, which conflicted with list.__iter__() API.
This patch drops _hybrid.__iter__() and makes stringify/flatten functions
unwrap a generator instead.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 04 Apr 2017 22:19:02 +0900 |
parents | 654e9a1c8a6c |
children | e5eab0fe69ee |
comparison
equal
deleted
inserted
replaced
31879:868ec199cad0 | 31880:a0f2d83f8083 |
---|---|
348 @templatefilter('stringify') | 348 @templatefilter('stringify') |
349 def stringify(thing): | 349 def stringify(thing): |
350 """Any type. Turns the value into text by converting values into | 350 """Any type. Turns the value into text by converting values into |
351 text and concatenating them. | 351 text and concatenating them. |
352 """ | 352 """ |
353 thing = templatekw.unwraphybrid(thing) | |
353 if util.safehasattr(thing, '__iter__') and not isinstance(thing, str): | 354 if util.safehasattr(thing, '__iter__') and not isinstance(thing, str): |
354 return "".join([stringify(t) for t in thing if t is not None]) | 355 return "".join([stringify(t) for t in thing if t is not None]) |
355 if thing is None: | 356 if thing is None: |
356 return "" | 357 return "" |
357 return str(thing) | 358 return str(thing) |