Skip to content

Commit

Permalink
fix: mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravencentric committed Aug 10, 2024
1 parent 198e603 commit 6affdcf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/archivefile/_adapters/_rar.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def read_bytes(self, member: StrPath | ArchiveMember) -> bytes:
try:
# ZipFile and TarFile raise KeyError but RarFile raises it's own NoRarEntry
# So for consistency's sake, we'll also raise KeyError here
return self._rarfile.read(name, pwd=self._password)
return self._rarfile.read(name, pwd=self._password) # type: ignore
except NoRarEntry:
raise KeyError(f"{name} not found in {self._file}")

Expand Down
20 changes: 12 additions & 8 deletions src/archivefile/_adapters/_sevenzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,19 @@ def read_bytes(self, member: StrPath | ArchiveMember) -> bytes:
if name not in self._sevenzipfile.getnames():
raise KeyError(f"{name} not found in {self._file}")

datadict = self._sevenzipfile.read(targets=[name])

if fileobj := datadict.get(name):
data = fileobj.read()
else:
data = b""

data = self._sevenzipfile.read(targets=[name])
self._sevenzipfile.reset()
return data

match data:
case None:
return b""
case dict():
if fileobj := data.get(name):
return fileobj.read() # type: ignore
else:
return b""
case _:
return b""

def read_text(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/archivefile/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def compression_type(self) -> CompressionType | None:
@property
def compression_level(self) -> CompressionLevel | None:
"""Compression level used for writing."""
return self._adapter.compression_level # type: ignore
return self._adapter.compression_level

@property
def adapter(self) -> str:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_writeall.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@pytest.mark.parametrize("mode", modes)
def test_writeall(tmp_path: Path, mode: str, extension: str) -> None:
dir = tmp_path / f"{uuid4()}.{extension}"
with ArchiveFile(dir, mode) as archive: # type: ignore
with ArchiveFile(dir, mode) as archive:
archive.writeall(ARCHIVE_DIR, glob="*.py")

with ArchiveFile(dir, "r") as archive:
Expand All @@ -46,7 +46,7 @@ def test_writeall(tmp_path: Path, mode: str, extension: str) -> None:
@pytest.mark.parametrize("mode", modes)
def test_writeall_with_root(tmp_path: Path, mode: str, extension: str) -> None:
dir = tmp_path / f"{uuid4()}.{extension}"
with ArchiveFile(dir, mode) as archive: # type: ignore
with ArchiveFile(dir, mode) as archive:
archive.writeall(ARCHIVE_DIR, glob="*.py", root=ARCHIVE_DIR.parent.parent)

with ArchiveFile(dir, "r") as archive:
Expand Down

0 comments on commit 6affdcf

Please sign in to comment.