From: Noah Morrison Date: Fri, 24 Aug 2018 00:22:34 +0000 (-0400) Subject: Allow for custom falsy data types X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=f0c15a019be645ac8c151b35a62417f3795c9d10;p=chevron.git Allow for custom falsy data types Helps resolve Issue #35 This allows for a custom data type be outputed even when falsy --- 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