From c450567d2626fe707725e8d57ebc64e75833b31d Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Sat, 2 Jan 2021 10:19:19 -0800 Subject: [PATCH] Use getattr instead of _asdict/__getitem__ `_asdict` is not public API for `namedtuple`. You may want to consider using the built-in `string` module, which implements this kind of `.0`/`.foo` formatting. --- chevron/renderer.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/chevron/renderer.py b/chevron/renderer.py index 56a55bf..50d2e32 100644 --- a/chevron/renderer.py +++ b/chevron/renderer.py @@ -67,16 +67,10 @@ def _get_key(key, scopes, warn=False): scope = scope[child] except (TypeError, AttributeError): try: - # Try namedtuple (which does not have __dict__ in - # Python 3: https://bugs.python.org/issue24931) - scope = scope._asdict()[child] + scope = getattr(scope, child) except (TypeError, AttributeError): - try: - # Try the dictionary (Complex types) - scope = scope.__dict__[child] - except (TypeError, AttributeError): - # Try as a list - scope = scope[int(child)] + # Try as a list + scope = scope[int(child)] # Return an empty string if falsy, with two exceptions # 0 should return 0, and False should return False -- 2.47.3