Skip to content

Commit 63561e1

Browse files
authored
fix: util.Namespace follows Attribute protocol so inspect/pytest/et al work again (#270)
I make use of `signxml` for SAML XML verification. I recently tried to make `pytest` validate all my doctests, however due to `util.Namespace` not following the Attribute protocol (i.e. an override of `__getattr__`) -- on missing attributes, one should **always** raise `AttributeError` as that allows any introspection via the `inspect` module to "Just Work". I was able to diagnose that the error was identical to pytest-dev/pytest#5080 and that a remediation was simply catching `KeyError` and re-raising as `AttributeError`.
1 parent f7080de commit 63561e1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

signxml/util/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525

2626
class Namespace(dict):
2727
def __getattr__(self, a):
28-
return dict.__getitem__(self, a)
28+
try:
29+
return dict.__getitem__(self, a)
30+
except KeyError:
31+
raise AttributeError(a) from None
2932

3033

3134
namespaces = Namespace(

0 commit comments

Comments
 (0)