Skip to content

Commit 26999e0

Browse files
committed
docs(import[provenance]) Explain why metadata None guard excludes type(None)
why: The isinstance guard was changed from (dict, type(None)) to dict to fix a TypeError, but lacks context on why None is unsafe. Without the comment a future developer might re-introduce type(None) thinking setdefault handles it. what: - Add inline comment above the UPDATE_URL metadata guard explaining that setdefault returns existing None instead of replacing it - Add same comment above the SKIP_UNCHANGED metadata guard
1 parent 039db68 commit 26999e0

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/vcspull/cli/import_cmd/_common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,8 @@ def _run_import(
955955
updated["repo"] = incoming_url
956956
updated.pop("url", None)
957957
if import_source:
958+
# None is not safe: setdefault returns existing None
959+
# instead of replacing it, causing TypeError.
958960
if not isinstance(updated.get("metadata"), dict):
959961
updated["metadata"] = {}
960962
metadata = updated.setdefault("metadata", {})
@@ -975,6 +977,8 @@ def _run_import(
975977
)
976978
if needs_tag:
977979
if not dry_run:
980+
# None is not safe: setdefault returns existing
981+
# None instead of replacing it, causing TypeError.
978982
if not isinstance(existing_meta, dict):
979983
live["metadata"] = {}
980984
live.setdefault("metadata", {})["imported_from"] = (

0 commit comments

Comments
 (0)