diff --git a/ops/__init__.py b/ops/__init__.py index 465ac2b94..4cda2bca5 100644 --- a/ops/__init__.py +++ b/ops/__init__.py @@ -20,8 +20,8 @@ the base class for charm libraries. - :class:`~ops.framework.EventBase` class and individual event types, like the :class:`~ops.ActionEvent` class. -- :class:`~ops.Framework` class, accessible as ``self.framework`` in a charm, - the main interface for the charm to `ops` library infrastructure, including: +- :class:`~ops.Framework` class, the main interface for the charm to `ops` library + infrastructure, including: - :attr:`~ops.Framework.on` shorthand property used to :meth:`~ops.Framework.observe` and react to Juju events. diff --git a/ops/_private/harness.py b/ops/_private/harness.py index 92fdeec5a..798a9ae1d 100644 --- a/ops/_private/harness.py +++ b/ops/_private/harness.py @@ -1915,10 +1915,9 @@ def get_filesystem_root(self, container: Union[str, Container]) -> pathlib.Path: # charm.py class ExampleCharm(ops.CharmBase): - def __init__(self, *args): - super().__init__(*args) - self.framework.observe(self.on["mycontainer"].pebble_ready, - self._on_pebble_ready) + def __init__(self, framework: ops.Framework): + super().__init__(framework) + framework.observe(self.on["mycontainer"].pebble_ready, self._on_pebble_ready) def _on_pebble_ready(self, event: ops.PebbleReadyEvent): self.hostname = event.workload.pull("/etc/hostname").read() diff --git a/ops/charm.py b/ops/charm.py index d58b8adde..98bb8b1ac 100644 --- a/ops/charm.py +++ b/ops/charm.py @@ -1137,8 +1137,8 @@ class CollectStatusEvent(LifecycleEvent): requires a "port" config option set before it can proceed:: class MyCharm(ops.CharmBase): - def __init__(self, *args): - super().__init__(*args) + def __init__(self, framework: ops.Framework): + super().__init__(framework) self.webapp = Webapp(self) # initialize other components @@ -1182,7 +1182,7 @@ class CharmEvents(ObjectEvents): By default, the events listed as attributes of this class will be provided via the :attr:`CharmBase.on` attribute. For example:: - self.framework.observe(self.on.config_changed, self._on_config_changed) + framework.observe(self.on.config_changed, self._on_config_changed) In addition to the events listed as attributes of this class, dynamically-named events will also be defined based on the charm's @@ -1191,8 +1191,8 @@ class CharmEvents(ObjectEvents): ``self.on[].`` or using a prefix like ``self.on._``, for example:: - self.framework.observe(self.on["db"].relation_created, self._on_db_relation_created) - self.framework.observe(self.on.workload_pebble_ready, self._on_workload_pebble_ready) + framework.observe(self.on["db"].relation_created, self._on_db_relation_created) + framework.observe(self.on.workload_pebble_ready, self._on_workload_pebble_ready) """ # NOTE: The one-line docstrings below are copied from the first line of @@ -1302,10 +1302,10 @@ class CharmBase(Object): import ops class MyCharm(ops.CharmBase): - def __init__(self, *args): - super().__init__(*args) - self.framework.observe(self.on.config_changed, self._on_config_changed) - self.framework.observe(self.on.stop, self._on_stop) + def __init__(self, framework: ops.Framework): + super().__init__(framework) + framework.observe(self.on.config_changed, self._on_config_changed) + framework.observe(self.on.stop, self._on_stop) # ... if __name__ == "__main__":