Skip to content

Commit 0c6cc45

Browse files
Copilotmnriem
andauthored
Fix type hint, add null checks for tf.extractfile() return value
Agent-Logs-Url: https://github.com/github/spec-kit/sessions/9fb9a8ea-0967-4baf-b95c-7101e423ff58 Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com>
1 parent d78ead1 commit 0c6cc45

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/specify_cli/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4331,12 +4331,16 @@ def extension_update(
43314331
# First try root-level extension.yml
43324332
try:
43334333
m = tf.getmember("extension.yml")
4334-
manifest_data = yaml.safe_load(tf.extractfile(m).read()) or {}
4334+
f = tf.extractfile(m)
4335+
if f is not None:
4336+
manifest_data = yaml.safe_load(f.read()) or {}
43354337
except KeyError:
43364338
# Look for extension.yml in a single top-level subdirectory
43374339
members = [m for m in tf.getmembers() if m.name.endswith("/extension.yml") and m.name.count("/") == 1]
43384340
if len(members) == 1:
4339-
manifest_data = yaml.safe_load(tf.extractfile(members[0]).read()) or {}
4341+
f = tf.extractfile(members[0])
4342+
if f is not None:
4343+
manifest_data = yaml.safe_load(f.read()) or {}
43404344
else:
43414345
with zipfile.ZipFile(zip_path, "r") as zf:
43424346
namelist = zf.namelist()
@@ -4928,7 +4932,9 @@ def _extract_workflow_yml(archive_path: Path, archive_fmt: str) -> bytes:
49284932
with tarfile.open(archive_path, "r:gz") as tf:
49294933
# Try root-level first.
49304934
try:
4931-
return tf.extractfile(tf.getmember("workflow.yml")).read()
4935+
f = tf.extractfile(tf.getmember("workflow.yml"))
4936+
if f is not None:
4937+
return f.read()
49324938
except KeyError:
49334939
pass
49344940
# Look in a single top-level subdirectory.
@@ -4937,7 +4943,9 @@ def _extract_workflow_yml(archive_path: Path, archive_fmt: str) -> bytes:
49374943
if m.name.endswith("/workflow.yml") and m.name.count("/") == 1
49384944
]
49394945
if len(candidates) == 1:
4940-
return tf.extractfile(candidates[0]).read()
4946+
f = tf.extractfile(candidates[0])
4947+
if f is not None:
4948+
return f.read()
49414949
else:
49424950
with zipfile.ZipFile(archive_path, "r") as zf:
49434951
namelist = zf.namelist()

src/specify_cli/extensions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def _detect_archive_format(url: str, content_type: str = "") -> str:
146146
def _safe_extract_tarball(
147147
archive_path: Path,
148148
dest_dir: Path,
149-
error_class: type = Exception,
149+
error_class: "type[Exception]" = Exception,
150150
) -> None:
151151
"""Safely extract a ``.tar.gz`` or ``.tgz`` archive into *dest_dir*.
152152

0 commit comments

Comments
 (0)