Skip to content

Commit c8e3667

Browse files
fix: Implement safe cache name resolvers for xpehh_gwss and ihs_gwss (#1199)
Following the pattern from #1193, add _get_xpehh_gwss_cache_name() and _get_ihs_gwss_cache_name() resolver methods to safely handle cache name resolution with fallback defaults.
1 parent 4cde560 commit c8e3667

7 files changed

Lines changed: 42 additions & 82 deletions

File tree

malariagen_data/adar1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class Adar1(AnophelesDataResource):
7575
7676
"""
7777

78+
_xpehh_gwss_cache_name = XPEHH_GWSS_CACHE_NAME
79+
_ihs_gwss_cache_name = IHS_GWSS_CACHE_NAME
7880
_roh_hmm_cache_name = ROH_HMM_CACHE_NAME
7981

8082
def __init__(

malariagen_data/adir1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class Adir1(AnophelesDataResource):
7575
7676
"""
7777

78+
_xpehh_gwss_cache_name = XPEHH_GWSS_CACHE_NAME
79+
_ihs_gwss_cache_name = IHS_GWSS_CACHE_NAME
7880
_roh_hmm_cache_name = ROH_HMM_CACHE_NAME
7981

8082
def __init__(

malariagen_data/af1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class Af1(AnophelesDataResource):
7777
7878
"""
7979

80+
_xpehh_gwss_cache_name = XPEHH_GWSS_CACHE_NAME
81+
_ihs_gwss_cache_name = IHS_GWSS_CACHE_NAME
8082
_roh_hmm_cache_name = ROH_HMM_CACHE_NAME
8183

8284
def __init__(

malariagen_data/ag3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class Ag3(AnophelesDataResource):
155155
156156
"""
157157

158+
_xpehh_gwss_cache_name = XPEHH_GWSS_CACHE_NAME
159+
_ihs_gwss_cache_name = IHS_GWSS_CACHE_NAME
158160
_roh_hmm_cache_name = ROH_HMM_CACHE_NAME
159161

160162
def __init__(

malariagen_data/amin1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class Amin1(AnophelesDataResource):
7575
7676
"""
7777

78+
_xpehh_gwss_cache_name = XPEHH_GWSS_CACHE_NAME
79+
_ihs_gwss_cache_name = IHS_GWSS_CACHE_NAME
7880
_roh_hmm_cache_name = ROH_HMM_CACHE_NAME
7981

8082
def __init__(

malariagen_data/anopheles.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -178,46 +178,46 @@ def __init__(
178178
)
179179

180180
def _get_xpehh_gwss_cache_name(self):
181-
"""Safe resolver for xpehh gwss cache name.
181+
"""Safely resolve the xpehh gwss cache name.
182182
183-
Subclasses may define _xpehh_gwss_cache_name as a class attribute.
184-
This method safely retrieves it or returns a default if unavailable.
183+
Supports class attribute, property, or legacy method override.
184+
Falls back to the default "xpehh_gwss_v1" if resolution fails.
185+
186+
See also: https://github.com/malariagen/malariagen-data-python/issues/1151
185187
"""
186188
try:
187-
# Try to get the cache name from the instance (respects MRO)
188-
cache_name = getattr(self, "_xpehh_gwss_cache_name")
189-
# Validate it's actually a string, not a descriptor or other object
190-
if not isinstance(cache_name, str):
191-
raise TypeError(
192-
f"_xpehh_gwss_cache_name must resolve to a string, "
193-
f"got {type(cache_name).__name__}"
194-
)
195-
return cache_name
196-
except (AttributeError, TypeError):
197-
# Fallback to a generic cache name if subclass hasn't defined one
198-
# or if the attribute isn't a proper string
199-
return "xpehh_gwss_v1"
189+
name = self._xpehh_gwss_cache_name
190+
# Handle legacy case where _xpehh_gwss_cache_name might be a
191+
# callable method rather than a property or class attribute.
192+
if callable(name):
193+
name = name()
194+
if isinstance(name, str) and len(name) > 0:
195+
return name
196+
except NotImplementedError:
197+
pass
198+
# Fallback to default.
199+
return "xpehh_gwss_v1"
200200

201201
def _get_ihs_gwss_cache_name(self):
202-
"""Safe resolver for ihs gwss cache name.
202+
"""Safely resolve the ihs gwss cache name.
203203
204-
Subclasses may define _ihs_gwss_cache_name as a class attribute.
205-
This method safely retrieves it or returns a default if unavailable.
204+
Supports class attribute, property, or legacy method override.
205+
Falls back to the default "ihs_gwss_v1" if resolution fails.
206+
207+
See also: https://github.com/malariagen/malariagen-data-python/issues/1151
206208
"""
207209
try:
208-
# Try to get the cache name from the instance (respects MRO)
209-
cache_name = getattr(self, "_ihs_gwss_cache_name")
210-
# Validate it's actually a string, not a descriptor or other object
211-
if not isinstance(cache_name, str):
212-
raise TypeError(
213-
f"_ihs_gwss_cache_name must resolve to a string, "
214-
f"got {type(cache_name).__name__}"
215-
)
216-
return cache_name
217-
except (AttributeError, TypeError):
218-
# Fallback to a generic cache name if subclass hasn't defined one
219-
# or if the attribute isn't a proper string
220-
return "ihs_gwss_v1"
210+
name = self._ihs_gwss_cache_name
211+
# Handle legacy case where _ihs_gwss_cache_name might be a
212+
# callable method rather than a property or class attribute.
213+
if callable(name):
214+
name = name()
215+
if isinstance(name, str) and len(name) > 0:
216+
return name
217+
except NotImplementedError:
218+
pass
219+
# Fallback to default.
220+
return "ihs_gwss_v1"
221221

222222
@staticmethod
223223
def _make_gene_cnv_label(gene_id, gene_name, cnv_type):

tests/anoph/test_cache_name_resolvers.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)