# HG changeset patch # User cmlenz # Date 1156848993 0 # Node ID 75c9c019de88040ad9fb497f3894ce03d5df02d6 # Parent b700e5326421e51f80eaadb7ffba92ab34fe18cd `TypeError`s raised by `py:def` macros (and other expressions producing streams) are no longer silently ignored. Closes #44. diff --git a/markup/template.py b/markup/template.py --- a/markup/template.py +++ b/markup/template.py @@ -961,15 +961,16 @@ # Test if the expression evaluated to an iterable, in which # case we yield the individual items try: - substream = _ensure(result) + substream = _ensure(iter(result)) + except TypeError: + # Neither a string nor an iterable, so just pass it + # through + yield TEXT, unicode(result), pos + else: for filter_ in filters: substream = filter_(substream, ctxt) for event in substream: yield event - except TypeError: - # Neither a string nor an iterable, so just pass it - # through - yield TEXT, unicode(result), pos else: yield kind, data, pos diff --git a/markup/tests/template.py b/markup/tests/template.py --- a/markup/tests/template.py +++ b/markup/tests/template.py @@ -319,6 +319,17 @@

bar

""", str(tmpl.generate())) + def test_function_raising_typeerror(self): + def badfunc(): + raise TypeError + tmpl = Template(""" +
+ ${badfunc()} +
+
+ """) + self.assertRaises(TypeError, list, tmpl.generate(badfunc=badfunc)) + class ForDirectiveTestCase(unittest.TestCase): """Tests for the `py:for` template directive."""