Skip to content

[BUG] AptaTrans.__init__() raises AssertionError instead of ValueError for invalid input #658

@onkar717

Description

@onkar717

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
pyaptamer 0.1.0a1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions