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

1from __future__ import annotations 

2 

3from abc import ABC, abstractmethod 

4from collections.abc import Iterator 

5from typing import TYPE_CHECKING 

6 

7if TYPE_CHECKING: 

8 from ..blob import BytesBlob 

9 

10 

11class ImmutableBlobDictBase(ABC): 

12 def __len__(self) -> int: 

13 return sum(1 for _ in self) 

14 

15 @abstractmethod 

16 def __contains__(self, key: str) -> bool: 

17 ... 

18 

19 @abstractmethod 

20 def get(self, key: str, default: BytesBlob | None = None) -> BytesBlob | None: 

21 ... 

22 

23 def __getitem__(self, key: str) -> BytesBlob: 

24 blob: BytesBlob | None = self.get(key) 

25 if blob is None: 

26 raise KeyError 

27 

28 return blob 

29 

30 @abstractmethod 

31 def __iter__(self) -> Iterator[str]: 

32 ... 

33 

34 

35class BlobDictBase(ImmutableBlobDictBase, ABC): 

36 @abstractmethod 

37 def clear(self) -> None: 

38 ... 

39 

40 @abstractmethod 

41 def pop(self, key: str, default: BytesBlob | None = None) -> BytesBlob | None: 

42 ... 

43 

44 def __delitem__(self, key: str) -> None: 

45 if key not in self: 

46 raise KeyError 

47 

48 self.pop(key) 

49 

50 @abstractmethod 

51 def __setitem__(self, key: str, blob: BytesBlob) -> None: 

52 ...