Skip to content

Add __repr__ to Region and CacheMiss utility classes (fixes #1219)#1220

Merged
jonbrenas merged 3 commits intomalariagen:masterfrom
Yashsingh045:GH1219-add-repr-region-cachemiss
Mar 24, 2026
Merged

Add __repr__ to Region and CacheMiss utility classes (fixes #1219)#1220
jonbrenas merged 3 commits intomalariagen:masterfrom
Yashsingh045:GH1219-add-repr-region-cachemiss

Conversation

@Yashsingh045
Copy link
Contributor

Summary

Fixes #1219.

The Region class had a useful __str__ but no __repr__, meaning it displayed as an unhelpful <malariagen_data.util.Region object at 0x...> inside lists, dicts, and REPL sessions. Similarly CacheMiss was a bare Exception subclass with no message formatting.

Changes

malariagen_data/util.py

Region.__repr__ — returns a constructor-style string:

>>> Region('2L', 100_000, 200_000)
Region('2L', 100000, 200000)
>>> [Region('2L'), Region('3R', 10, 20)]
[Region('2L', None, None), Region('3R', 10, 20)]

(the existing __str__ format is unchanged: '2L:100,000-200,000')

CacheMiss — adds a docstring, default message, and __repr__:

>>> str(CacheMiss())
'Cache miss: requested item not found in cache.'
>>> str(CacheMiss('my_key'))
"Cache miss for key: 'my_key'"
>>> repr(CacheMiss('my_key'))
"CacheMiss('my_key')"

tests/test_util.py (new file)

Unit tests covering all the above behaviours.

Testing

All existing tests continue to pass. New tests added in tests/test_util.py.

…riagen#1219)

- Region.__repr__ returns a constructor-style string, e.g. Region('2L', 100000, 200000)
  so that Region objects display usefully inside lists, dicts, and REPL sessions,
  complementing the existing __str__ (e.g. '2L:100,000-200,000').

- CacheMiss gains a default message and __repr__:
  - CacheMiss()          → str 'Cache miss: requested item not found in cache.'
  - CacheMiss('key')     → str "Cache miss for key: 'key'"
  - repr(CacheMiss('k')) → "CacheMiss('k')"

- Added tests/test_util.py covering both classes.
@Yashsingh045
Copy link
Contributor Author

hey @jonbrenas ,
Could you please review this PR?

@Yashsingh045 Yashsingh045 requested a review from jonbrenas March 24, 2026 11:39
@Yashsingh045
Copy link
Contributor Author

hey @jonbrenas ,
I have fixed the lint error.
Could you please review this PR?

@Yashsingh045
Copy link
Contributor Author

Hi @jonbrenas ,
Just a gentle reminder, Please review this PR when you have time.
Thanks

@jonbrenas jonbrenas merged commit 49fcc68 into malariagen:master Mar 24, 2026
8 checks passed
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.

Add __repr__ to Region and CacheMiss utility classes for better debugging

2 participants