comparison configmix/config.py @ 104:d9f9a06e0c49

Make a better error message for "TypeError" exceptions when looking up variables. Otherwise -- if a key exists but if it's not a dict as expected a TypeError is throws that nobody does understand.
author Franz Glasner <f.glasner@feldmann-mg.com>
date Fri, 23 Mar 2018 17:25:21 +0100
parents 218807d7d883
children a5339d39af5c
comparison
equal deleted inserted replaced
103:2eac386f825a 104:d9f9a06e0c49
152 parts = key.split('.') 152 parts = key.split('.')
153 try: 153 try:
154 v = self[parts[0]] 154 v = self[parts[0]]
155 for p in parts[1:]: 155 for p in parts[1:]:
156 v = v[p] 156 v = v[p]
157 except TypeError:
158 raise KeyError("Configuration variable %r not found (missing intermediate keys?)" % key)
157 except KeyError: 159 except KeyError:
158 if default is _MARKER: 160 if default is _MARKER:
159 raise KeyError("Configuration variable %r not found" % key) 161 raise KeyError("Configuration variable %r not found" % key)
160 else: 162 else:
161 return default 163 return default