fix: replace assert isinstance(...) statements with proper TypeError exceptions across codebase#1042
Open
suhaan-24 wants to merge 3 commits intomalariagen:masterfrom
Open
Conversation
Contributor
Author
|
Hey @jonbrenas all checks are passed please have a look at this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR replaces 13
assert isinstance(...)statements across 4 files with explicitif not isinstance(...): raise TypeError(...)blocks, following the same pattern established in #1033.Why this matters
Python's
assertstatements are silently removed when running with optimisation flags (python -O), making them unreliable for runtime type checking. The newTypeErrorexceptions include descriptive messages showing the expected vs actual type, making debugging easier for users.Changes
frq_base.py— replaced 2 type assertions in plotting functionscnv_frq.py— replaced 3 type assertions in gene CNV frequency methodssample_metadata.py— replaced 5 type assertions in sample lookup and cohort setup methodsutil.py— replaced 3 type assertions in internal helpersVerification
All 150 relevant tests pass, and there are no changes to behaviour for valid inputs.
Closes #1041