Skip to content

fix: replace truthiness checks with is not None in PlasmodiumDataResource._subset_genome_sequence_region#1109

Open
Gopisokk wants to merge 1 commit intomalariagen:masterfrom
Gopisokk:GH-fix-plasmodium-truthiness-bug
Open

fix: replace truthiness checks with is not None in PlasmodiumDataResource._subset_genome_sequence_region#1109
Gopisokk wants to merge 1 commit intomalariagen:masterfrom
Gopisokk:GH-fix-plasmodium-truthiness-bug

Conversation

@Gopisokk
Copy link

What problem does this solve?

_subset_genome_sequence_region() in plasmodium.py uses truthiness checks (if region.start: / if region.end:) to decide whether to slice the genome sequence. Because Python evaluates 0 as falsy, specifying region.start = 0 silently skips slicing and returns the entire contig instead of the requested sub-region.

This is the same class of bug as #940, but in the Plasmodium codebase (PlasmodiumDataResource) which is not covered by that issue.

How does it solve it?

Replace the truthiness checks with explicit None checks:

-        if region.start:
+        if region.start is not None:
             slice_start = region.start - 1
         else:
             slice_start = None
-        if region.end:
+        if region.end is not None:
             slice_stop = region.end
         else:
             slice_stop = None

This correctly distinguishes between "no boundary specified" (None) and "boundary is zero" (0).

Also fixes a docstring typo: SebsetSubset.

Relevant issues

Related: #940

Testing done

  • Pre-commit hooks (ruff lint, ruff format, trailing whitespace, end of files) all pass ✅

Breaking changes

None. This fix restores the expected behavior for edge-case inputs that were previously silently mishandled.
Closes #1108

…urce._subset_genome_sequence_region

When 
egion.start is 0, Python evaluates it as falsy, causing the
slicing logic to be silently skipped and the full contig to be returned
instead of the requested sub-region.

Replace if region.start: and if region.end: with explicit
if region.start is not None: and if region.end is not None: checks
to correctly distinguish between 'no boundary specified' (None) and
'boundary is zero' (0).

Also fix docstring typo: 'Sebset' -> 'Subset'.

Related: malariagen#940
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.

Plasmodium _subset_genome_sequence_region has the same truthiness bug

1 participant