mirror of
https://github.com/bugsink/bugsink.git
synced 2026-01-06 05:10:15 -06:00
AttrLike dict: better exceptions
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user