From c6573407a7d24cf198bba01df91f044f68ac40f7 Mon Sep 17 00:00:00 2001 From: Dima Tisnek Date: Fri, 27 Sep 2024 14:07:17 +0900 Subject: [PATCH] fix: explicit is better than implicit --- juju/application.py | 35 +++++++++++++++++++---------------- juju/model.py | 4 ++-- juju/origin.py | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/juju/application.py b/juju/application.py index e102d52e..9487c780 100644 --- a/juju/application.py +++ b/juju/application.py @@ -659,27 +659,27 @@ async def set_constraints(self, constraints): async def refresh( self, - channel=None, - force=False, - force_series=False, - force_units=False, + channel: Optional[str] = None, + force: bool = False, + force_series: bool = False, + force_units: bool = False, path: Optional[Union[Path, str]] = None, - resources=None, - revision=None, + resources: Optional[Dict[str, str]] = None, + revision: Optional[int] = None, switch: Optional[str] = None, ): """Refresh the charm for this application. - :param str channel: Channel to use when getting the charm from the + :param str|None channel: Channel to use when getting the charm from the charm store, e.g. 'development' :param bool force_series: Refresh even if series of deployed application is not supported by the new charm :param bool force_units: Refresh all units immediately, even if in error state - :param Path|str path: Refresh to a charm located at path - :param dict resources: Dictionary of resource name/filepath pairs - :param int revision: Explicit refresh revision - :param str switch: Crossgrade charm url + :param Path|str|None path: Refresh to a charm located at path + :param dict[str,str]|None resources: Dictionary of resource name/filepath pairs + :param int|None revision: Explicit refresh revision + :param str|None switch: URL of a different charm to cross-grade to """ if switch is not None and path is not None: @@ -931,14 +931,17 @@ async def get_metrics(self): return await self.model.get_metrics(self.tag) -def _refresh_origin(current_origin: client.CharmOrigin, channel=None, revision=None) -> client.CharmOrigin: - if channel is not None: - channel = Channel.parse(channel).normalize() +def _refresh_origin( + current_origin: client.CharmOrigin, + channel: Optional[str] = None, + revision: Optional[int] = None, + ) -> client.CharmOrigin: + chan = None if channel is None else Channel.parse(channel).normalize() return client.CharmOrigin( source=current_origin.source, - track=channel.track if channel else current_origin.track, - risk=channel.risk if channel else current_origin.risk, + track=chan.track if chan else current_origin.track, + risk=chan.risk if chan else current_origin.risk, revision=revision if revision is not None else current_origin.revision, base=current_origin.base, architecture=current_origin.get('architecture', DEFAULT_ARCHITECTURE), diff --git a/juju/model.py b/juju/model.py index a51944de..f3b274b1 100644 --- a/juju/model.py +++ b/juju/model.py @@ -2013,8 +2013,8 @@ async def add_local_resources(self, application, entity_url, metadata, resources :param str application: the name of the application :param client.CharmURL entity_url: url for the charm that we add resources for :param [string]string metadata: metadata for the charm that we add resources for - :param [string] resources: the paths for the local files (or oci-images) to be added as - local resources + :param dict[str, str] resources: the paths for the local files (or oci-images) to + be added as local resources :returns [string]string resource_map that is a map of resources to their assigned pendingIDs. diff --git a/juju/origin.py b/juju/origin.py index bb68596b..7f12d745 100644 --- a/juju/origin.py +++ b/juju/origin.py @@ -69,7 +69,7 @@ def __init__(self, track=None, risk=None): self.risk = risk @staticmethod - def parse(s): + def parse(s: str): """parse a channel from a given string. Parse does not take into account branches.