Skip to content

fix: handle indefinite Range bound of 0 in normalize - #688

Open
syahra712 wants to merge 1 commit into
ga4gh:mainfrom
syahra712:fix/normalize-range-zero
Open

syahra712 wants to merge 1 commit into
ga4gh:mainfrom
syahra712:fix/normalize-range-zero

Conversation

@syahra712

Copy link
Copy Markdown
Contributor

normalize() raises a TypeError for an allele whose location has an indefinite range with 0 as its defined bound, e.g. start=Range([0, None]) or end=Range([0, None]):

TypeError: '>' not supported between instances of 'NoneType' and 'int'

_get_allele_location_pos chose the defined bound with pos.root[0] or pos.root[1]. Because 0 is falsy, Range([0, None]) gave val=None, which then reached bioutils' normalize. Range([1, None]) and Range([None, 0]) worked, so only a 0 lower bound on an open-upper range was affected.

The fix picks the defined side explicitly: pos.root[1] if pos0_is_none else pos.root[0].

Tests

Two cases added to normalize_location_in_bounds_cases (local test SeqRepo, no cassettes):

  • start=[0, None], end=1 substitution
  • start=[None, 0], end=[0, None] insertion

Both fail on main with the TypeError above and pass with this change. ruff check and ruff format --check are clean.

_get_allele_location_pos picked the defined bound of an indefinite Range
with `pos.root[0] or pos.root[1]`, so a bound of 0 (e.g. Range([0, None]))
was treated as missing and val became None, which made normalize() raise
a TypeError. Pick the defined side explicitly instead.
@syahra712
syahra712 requested review from a team as code owners November 7, 2026 10:05

This branch has not been deployed

No deployments
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.

1 participant