[formatter] support putting keys in quotes

i.e. obj["key"] or obj['key']
as in f-strings
pull/3849/head
Mike Fährmann 2 years ago
parent 46fdf46f21
commit fe41a2b159
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -256,6 +256,8 @@ def parse_field_name(field_name):
try:
if ":" in key:
key = _slice(key)
else:
key = key.strip("\"'")
except TypeError:
pass # key is an integer

@ -128,6 +128,11 @@ class TestFormatter(unittest.TestCase):
self._run_test("{l[0]}" , "a")
self._run_test("{a[6]}" , "w")
def test_dict_access(self):
self._run_test("{d[a]}" , "foo")
self._run_test("{d['a']}", "foo")
self._run_test('{d["a"]}', "foo")
def test_slicing(self):
v = self.kwdict["a"]
self._run_test("{a[1:10]}" , v[1:10])

Loading…
Cancel
Save