From 0e29029aecf3e6dcd260fe88e58d29bc3b6ebcfb Mon Sep 17 00:00:00 2001 From: PietroPasotti Date: Mon, 31 Jul 2023 23:49:03 +0200 Subject: [PATCH] effectively disable type checking on ObjectEvent namespace (#982) Co-authored-by: Ben Hoyt --- ops/framework.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ops/framework.py b/ops/framework.py index b49ed4b4e..df9aa1bb2 100755 --- a/ops/framework.py +++ b/ops/framework.py @@ -489,6 +489,14 @@ def __repr__(self): event_kinds = ', '.join(sorted(self._event_kinds())) return f'<{k.__module__}.{k.__qualname__}: {event_kinds}>' + def __getattr__(self, name: str) -> Any: + """The existence of this method tells type checkers to allow dynamic attributes. + + This allows charms to access dynamically-defined events such as + ``self.on.db_relation_joined`` without Mypy/Pyright whining. + """ + return super().__getattribute__(name) + class PrefixedEvents: """Events to be found in all events using a specific prefix."""