Coverage for src/blob_dict/dict/__init__.py: 0%
37 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-03-27 22:31 -0700
« prev ^ index » next coverage.py v7.7.1, created at 2025-03-27 22:31 -0700
1from __future__ import annotations
3from abc import ABC, abstractmethod
4from collections.abc import Iterator
5from typing import TYPE_CHECKING
7if TYPE_CHECKING:
8 from ..blob import BytesBlob
11class ImmutableBlobDictBase(ABC):
12 def __len__(self) -> int:
13 return sum(1 for _ in self)
15 @abstractmethod
16 def __contains__(self, key: str) -> bool:
17 ...
19 @abstractmethod
20 def get(self, key: str, default: BytesBlob | None = None) -> BytesBlob | None:
21 ...
23 def __getitem__(self, key: str) -> BytesBlob:
24 blob: BytesBlob | None = self.get(key)
25 if blob is None:
26 raise KeyError
28 return blob
30 @abstractmethod
31 def __iter__(self) -> Iterator[str]:
32 ...
35class BlobDictBase(ImmutableBlobDictBase, ABC):
36 @abstractmethod
37 def clear(self) -> None:
38 ...
40 @abstractmethod
41 def pop(self, key: str, default: BytesBlob | None = None) -> BytesBlob | None:
42 ...
44 def __delitem__(self, key: str) -> None:
45 if key not in self:
46 raise KeyError
48 self.pop(key)
50 @abstractmethod
51 def __setitem__(self, key: str, blob: BytesBlob) -> None:
52 ...