Skip to content

Commit

Permalink
fix: util.Namespace follows Attribute protocol so inspect/pytest/et a…
Browse files Browse the repository at this point in the history
…l 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`.
  • Loading branch information
autumnjolitz authored Dec 7, 2024
1 parent f7080de commit 63561e1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion signxml/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

class Namespace(dict):
def __getattr__(self, a):
return dict.__getitem__(self, a)
try:
return dict.__getitem__(self, a)
except KeyError:
raise AttributeError(a) from None


namespaces = Namespace(
Expand Down

0 comments on commit 63561e1

Please sign in to comment.