Describe the bug
AptaTrans.__init__() raises AssertionError when in_dim is not divisible by n_heads. This is user-facing input validation, not an internal invariant check — the correct exception type is ValueError.
Using AssertionError for input validation is an anti-pattern because:
AssertionError signals broken internal assumptions, not bad user input
- Users may catch
ValueError but not AssertionError in their error handling
- It's inconsistent with Python and scikit-learn conventions
To Reproduce
from pyaptamer.aptatrans import AptaTrans, EncoderPredictorConfig
apta = EncoderPredictorConfig(128, 16, max_len=128)
prot = EncoderPredictorConfig(128, 16, max_len=128)
# Raises AssertionError instead of ValueError
model = AptaTrans(apta, prot, in_dim=128, n_heads=3)
# AssertionError: Input dimension 128 must be divisible by number of heads 3.
Expected behavior
Should raise ValueError with the same message, since this is validating a user-provided parameter value.
Additional context
- The docstring also contains a typo:
AssertionError (missing the 's' — though AssertionError is actually valid Python, the standard spelling is AssertionError)
- Scikit-learn and PyTorch conventions both use
ValueError for parameter validation
Versions
Details
Describe the bug
AptaTrans.__init__()raisesAssertionErrorwhenin_dimis not divisible byn_heads. This is user-facing input validation, not an internal invariant check — the correct exception type isValueError.Using
AssertionErrorfor input validation is an anti-pattern because:AssertionErrorsignals broken internal assumptions, not bad user inputValueErrorbut notAssertionErrorin their error handlingTo Reproduce
Expected behavior
Should raise
ValueErrorwith the same message, since this is validating a user-provided parameter value.Additional context
AssertionError(missing the 's' — thoughAssertionErroris actually valid Python, the standard spelling isAssertionError)ValueErrorfor parameter validationVersions
Details