Skip to content

Commit 309774b

Browse files
more typing fixes
1 parent 94d0ade commit 309774b

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/atmst/blockstore/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def del_block(self, key: bytes) -> None:
3333

3434

3535
class MemoryBlockStore(BlockStore):
36-
_state = Dict[bytes, bytes]
36+
_state: Dict[bytes, bytes]
3737

3838
def __init__(self, state: Optional[Dict[bytes, bytes]]=None) -> None:
3939
"""

src/atmst/blockstore/car_file.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,19 @@ def __init__(self, file: BinaryIO, validate_hashes: bool=True) -> None:
5656
if len(header) != header_len:
5757
raise EOFError("not enough CAR header bytes")
5858
header_obj = decode_dag_cbor(header)
59+
if not isinstance(header_obj, dict):
60+
raise TypeError
5961
if header_obj.get("version") != 1:
6062
raise ValueError(f"unsupported CAR version ({header_obj.get('version')})")
61-
if len(header_obj["roots"]) != 1:
62-
raise ValueError(f"unsupported number of CAR roots ({len(header_obj['roots'])}, expected 1)")
63-
self.car_root = header_obj["roots"][0]
63+
roots = header_obj["roots"]
64+
if not isinstance(roots, list):
65+
raise TypeError
66+
if len(roots) != 1:
67+
raise ValueError(f"unsupported number of CAR roots ({len(roots)}, expected 1)")
68+
root = roots[0]
69+
if not isinstance(root, CID):
70+
raise TypeError
71+
self.car_root = root
6472

6573
# scan through the CAR to find block offsets
6674
self.block_offsets = {}

src/atmst/cartool.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def open_car(car_path: str) -> Tuple[ReadOnlyCARBlockStore, dict]:
2020
carfile = open(car_path, "rb")
2121
bs = ReadOnlyCARBlockStore(carfile)
2222
commit = decode_dag_cbor(bs.get_block(bytes(bs.car_root)))
23+
if not isinstance(commit, dict):
24+
raise TypeError
2325
return bs, commit
2426

2527
def print_info(car_path: str) -> None:

0 commit comments

Comments
 (0)