From f0c15a019be645ac8c151b35a62417f3795c9d10 Mon Sep 17 00:00:00 2001 From: Noah Morrison Date: Thu, 23 Aug 2018 20:22:34 -0400 Subject: [PATCH] Allow for custom falsy data types Helps resolve Issue #35 This allows for a custom data type be outputed even when falsy --- chevron/renderer.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/chevron/renderer.py b/chevron/renderer.py index 4286f5b..9392bf0 100644 --- a/chevron/renderer.py +++ b/chevron/renderer.py @@ -65,7 +65,13 @@ def _get_key(key, scopes): if scope is False: return False - return scope or '' + try: + # This allows for custom falsy data types + # https://github.com/noahmorrison/chevron/issues/35 + if scope._CHEVRON_return_scope_when_falsy: + return scope + except AttributeError: + return scope or '' except (AttributeError, KeyError): # We couldn't find the key in the current scope # We'll try again on the next pass -- 2.47.3