Skip to content

Commit

Permalink
Type annotate PebbleReadyEvent.workload (#962)
Browse files Browse the repository at this point in the history
One more thing forgotten from #953. This is annoying because it
means that charms that use ops.PebbleReadyEvent annotations
when handling pebble-ready can't access any attributes of the
workload, as it doesn't have a type.
  • Loading branch information
benhoyt authored Jul 4, 2023
1 parent 384ef3a commit eb57958
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions ops/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,15 @@ class WorkloadEvent(HookEvent):
Workload events are generated for all containers that the charm
expects in metadata. Workload containers currently only trigger
a PebbleReadyEvent.
a :class:`PebbleReadyEvent`.
"""

workload: 'Container'
"""The workload involved in this event.
Attributes:
workload: The :class:`~ops.model.Container` involved in this event.
Workload currently only can be a Container but in future may
be other types that represent the specific workload type e.g.
a Machine.
Workload currently only can be a :class:`Container <model.Container>`, but
in future may be other types that represent the specific workload type,
for example a machine.
"""

def __init__(self, handle: 'Handle', workload: 'Container'):
Expand All @@ -670,7 +672,7 @@ def restore(self, snapshot: Dict[str, Any]):
if container_name:
self.workload = self.framework.model.unit.get_container(container_name)
else:
self.workload = None
self.workload = None # type: ignore


class PebbleReadyEvent(WorkloadEvent):
Expand Down

0 comments on commit eb57958

Please sign in to comment.