diff --git a/ops/model.py b/ops/model.py index 7fa8f3027..3bafa88ab 100644 --- a/ops/model.py +++ b/ops/model.py @@ -91,16 +91,6 @@ }) -# Copied from typeshed. -_KT = typing.TypeVar("_KT") -_VT_co = typing.TypeVar("_VT_co", covariant=True) - - -class _SupportsKeysAndGetItem(typing.Protocol[_KT, _VT_co]): - def keys(self) -> typing.Iterable[_KT]: ... - def __getitem__(self, __key: _KT) -> _VT_co: ... - - logger = logging.getLogger(__name__) MAX_LOG_LINE_LEN = 131071 # Max length of strings to pass to subshell. @@ -1722,7 +1712,7 @@ def __getitem__(self, key: str) -> str: self._validate_read() return super().__getitem__(key) - def update(self, other: _SupportsKeysAndGetItem[str, str], **kwargs: str): + def update(self, other: typing.Any = (), /, **kwargs: str): """Update the data from dict/iterable other and the kwargs.""" super().update(other, **kwargs) diff --git a/test/test_model.py b/test/test_model.py index 1f7c212a2..2037585b1 100644 --- a/test/test_model.py +++ b/test/test_model.py @@ -232,6 +232,32 @@ def test_get_app_relation_data(self, harness: ops.testing.Harness[ops.CharmBase] relation_id, harness.model.app) == harness.get_relation_data( relation_id, local_app) == {'foo': 'bar'} + @pytest.mark.parametrize('args,kwargs', [ + (({'foo': 'baz'}, ), {}), + (([('foo', 'baz')], ), {}), + ((), {'foo': 'baz'}) + ]) + def test_update_app_relation_data( + self, + args: typing.Tuple[typing.Any, ...], + kwargs: typing.Dict[str, str], + harness: ops.testing.Harness[ops.CharmBase], + ): + harness.set_leader(True) + harness.begin() + relation_id = harness.add_relation('db1', 'remote') + harness.add_relation_unit(relation_id, 'remote/0') + with harness._event_context('foo_event'): + harness.update_relation_data( + relation_id, + harness.model.app.name, + {'foo': 'bar'}) + rel = harness.model.get_relation('db1', relation_id) + assert rel is not None + rel.data[harness.model.app].update(*args, **kwargs) + assert harness.get_relation_data( + relation_id, harness.model.app) == {'foo': 'baz'} + def test_unit_relation_data(self, harness: ops.testing.Harness[ops.CharmBase]): relation_id = harness.add_relation('db1', 'remoteapp1') harness.add_relation_unit(relation_id, 'remoteapp1/0')