Skip to content

Commit

Permalink
effectively disable type checking on ObjectEvent namespace (#982)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Hoyt <[email protected]>
  • Loading branch information
PietroPasotti and benhoyt authored Jul 31, 2023
1 parent fad95d7 commit 0e29029
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ops/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 0e29029

Please sign in to comment.