Skip to content

Commit

Permalink
fix: explicit is better than implicit
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaqq committed Sep 27, 2024
1 parent 6c8d862 commit c657340
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
35 changes: 19 additions & 16 deletions juju/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions juju/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion juju/origin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c657340

Please sign in to comment.