Skip to content

fix: replace assert isinstance(...) statements with proper TypeError exceptions across codebase#1042

Open
suhaan-24 wants to merge 3 commits intomalariagen:masterfrom
suhaan-24:fix/replace-assert-isinstance-with-typeerror
Open

fix: replace assert isinstance(...) statements with proper TypeError exceptions across codebase#1042
suhaan-24 wants to merge 3 commits intomalariagen:masterfrom
suhaan-24:fix/replace-assert-isinstance-with-typeerror

Conversation

@suhaan-24
Copy link
Copy Markdown
Contributor

Summary

This PR replaces 13 assert isinstance(...) statements across 4 files with explicit if not isinstance(...): raise TypeError(...) blocks, following the same pattern established in #1033.

Why this matters

Python's assert statements are silently removed when running with optimisation flags (python -O), making them unreliable for runtime type checking. The new TypeError exceptions include descriptive messages showing the expected vs actual type, making debugging easier for users.

Changes

  • frq_base.py — replaced 2 type assertions in plotting functions
  • cnv_frq.py — replaced 3 type assertions in gene CNV frequency methods
  • sample_metadata.py — replaced 5 type assertions in sample lookup and cohort setup methods
  • util.py — replaced 3 type assertions in internal helpers

Verification

All 150 relevant tests pass, and there are no changes to behaviour for valid inputs.
Closes #1041

@suhaan-24
Copy link
Copy Markdown
Contributor Author

Hey @jonbrenas all checks are passed please have a look at this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace remaining assert isinstance(...) statements with proper TypeError exceptions across the codebase

1 participant