Skip to content

Commit

Permalink
Try making the get() method more explicit in its return type.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer committed Apr 10, 2024
1 parent edc5565 commit a32aea9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ops/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,13 @@ def __getitem__(self, key: str) -> str:
self._validate_read()
return cast(str, super().__getitem__(key))

# This is provided by Mapping, but we need to make the return type more explicit.
def get(self, key: str, default: str) -> str:
try:
return self.__getitem__(key)
except KeyError:
return default

def __delitem__(self, key: str):
self._validate_write(key, '')
# Match the behavior of Juju, which is that setting the value to an empty
Expand Down

0 comments on commit a32aea9

Please sign in to comment.