diff --git a/bugsink/app_settings.py b/bugsink/app_settings.py index cf66598..a3c9eb4 100644 --- a/bugsink/app_settings.py +++ b/bugsink/app_settings.py @@ -70,9 +70,15 @@ class AttrLikeDict(dict): return item in self def __getattr__(self, item): - if item not in self: - raise AttributeError(item) - return self[item] + # attribute errors are to be understood at the call site; as they are for regular object's missing attributes. + __tracebackhide__ = True + + try: + return self[item] + except KeyError: + # "from None": this is so directly caused by the KeyError that cause and effect are the same and cause must + # be hidden. + raise AttributeError(item) from None _settings = None diff --git a/snappea/settings.py b/snappea/settings.py index 03b7a4a..57fa9a1 100644 --- a/snappea/settings.py +++ b/snappea/settings.py @@ -36,8 +36,19 @@ DEFAULTS = { class AttrLikeDict(dict): + def __hasattr__(self, item): + return item in self + def __getattr__(self, item): - return self[item] + # attribute errors are to be understood at the call site; as they are for regular object's missing attributes. + __tracebackhide__ = True + + try: + return self[item] + except KeyError: + # "from None": this is so directly caused by the KeyError that cause and effect are the same and cause must + # be hidden. + raise AttributeError(item) from None _settings = None