Skip to content

Add __repr__ to Region and CacheMiss utility classes for better debugging #1219

@Yashsingh045

Description

@Yashsingh045

Problem

The Region class and CacheMiss exception in malariagen_data/util.py lack informative string representations for debugging.

  • Region has a __str__ method (e.g., "2L:100,000-200,000") but no __repr__. When a Region object appears inside a list, dict, or is inspected interactively in Python/Jupyter notebooks, you get the unhelpful default: <malariagen_data.util.Region object at 0x7f...>.

  • CacheMiss is a bare Exception subclass (class CacheMiss(Exception): pass) with no default message and no __repr__. When caught and printed during debugging, it shows as CacheMiss() with no context.

Evidence

In malariagen_data/util.py:

  • Region class (line ~542): has __str__ but no __repr__
  • CacheMiss class (line ~906): class CacheMiss(Exception): pass

Proposed Fix

  1. Add __repr__ to Region that returns a valid Python constructor-style string, e.g.:

    • Region('2L', 100000, 200000) → repr shows Region('2L', 100000, 200000)
  2. Add __repr__ (and optional default message) to CacheMiss for clearer output during debugging.

Impact

Better debugging experience for both users and developers. Small, targeted change with large UX improvement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions