Skip to content

[BUG] PositionalEncoding uses assert for input validation instead of raising an exception #353

@tarun-227

Description

@tarun-227

Describe the bug

In PositionalEncoding.forward(), the sequence length check uses assert instead of raising a proper exception. Assertions are stripped when Python is run with the -O (optimize) flag, meaning this validation silently disappears in production.

Relevant code:

  • pyaptamer/aptatrans/layers/_encoder.py, line 81
assert x.shape[1] <= self.max_len, (
    f"Input sequence length {x.shape[1]} exceeds maximum length {self.max_len}."
)

Expected behavior

Use an explicit ValueError instead of assert:

if x.shape[1] > self.max_len:
    raise ValueError(
        f"Input sequence length {x.shape[1]} exceeds maximum length {self.max_len}."
    )

This ensures the check always runs regardless of Python optimization flags.

Versions

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